Add prometheus2 configuration to the prometheus modules

As the configuration for the exporters and alertmanager is unchanged
between the two major versions this patch tries to minimize
duplication while at the same time as there's no upgrade path from 1.x
to 2.x, it allows running the two services in parallel. See also #56037
This commit is contained in:
Alberto Berti 2019-02-21 15:29:54 +01:00 committed by Jean-Baptiste Giraudeau
parent 373488e6f4
commit 11b89720b7
No known key found for this signature in database
GPG Key ID: E96EF57FD501B961
20 changed files with 1110 additions and 859 deletions

View File

@ -339,6 +339,7 @@
rss2email = 312; rss2email = 312;
cockroachdb = 313; cockroachdb = 313;
zoneminder = 314; zoneminder = 314;
prometheus2 = 315;
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
@ -638,6 +639,7 @@
rss2email = 312; rss2email = 312;
cockroachdb = 313; cockroachdb = 313;
zoneminder = 314; zoneminder = 314;
prometheus2 = 315;
# When adding a gid, make sure it doesn't match an existing # When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal # uid. Users and groups with the same name should have equal

View File

@ -4,31 +4,33 @@ with lib;
let let
cfg = config.services.prometheus.alertmanager; cfg = config.services.prometheus.alertmanager;
mkConfigFile = pkgs.writeText "alertmanager.yml" (builtins.toJSON cfg.configuration); cfg2 = config.services.prometheus2.alertmanager;
mkConfigFile = amCfg:
pkgs.writeText "alertmanager.yml" (builtins.toJSON amCfg.configuration);
checkedConfig = file: pkgs.runCommand "checked-config" { buildInputs = [ cfg.package ]; } '' mkAlertmanagerYml = amCfg: let
ln -s ${file} $out checkedConfig = file:
amtool check-config $out pkgs.runCommand "checked-config" { buildInputs = [ amCfg.package ]; } ''
''; ln -s ${file} $out
amtool check-config $out
'';
yml = if amCfg.configText != null then
pkgs.writeText "alertmanager.yml" amCfg.configText
else mkConfigFile amCfg;
in
checkedConfig yml;
alertmanagerYml = let mkCmdlineArgs = amCfg:
yml = if cfg.configText != null then amCfg.extraFlags ++ [
pkgs.writeText "alertmanager.yml" cfg.configText "--config.file ${mkAlertmanagerYml amCfg}"
else mkConfigFile; "--web.listen-address ${amCfg.listenAddress}:${toString amCfg.port}"
in checkedConfig yml; "--log.level ${amCfg.logLevel}"
] ++ (optional (amCfg.webExternalUrl != null)
cmdlineArgs = cfg.extraFlags ++ [ "--web.external-url ${amCfg.webExternalUrl}"
"--config.file ${alertmanagerYml}" ) ++ (optional (amCfg.logFormat != null)
"--web.listen-address ${cfg.listenAddress}:${toString cfg.port}" "--log.format ${amCfg.logFormat}"
"--log.level ${cfg.logLevel}" );
] ++ (optional (cfg.webExternalUrl != null) amOptions = {
"--web.external-url ${cfg.webExternalUrl}"
) ++ (optional (cfg.logFormat != null)
"--log.format ${cfg.logFormat}"
);
in {
options = {
services.prometheus.alertmanager = {
enable = mkEnableOption "Prometheus Alertmanager"; enable = mkEnableOption "Prometheus Alertmanager";
package = mkOption { package = mkOption {
@ -135,36 +137,44 @@ in {
''; '';
}; };
}; };
mkAMConfig = amCfg: amVersion:
config = mkMerge [
(mkIf amCfg.enable {
assertions = singleton {
assertion = amCfg.configuration != null || amCfg.configText != null;
message = "Can not enable alertmanager without a configuration. "
+ "Set either the `configuration` or `configText` attribute.";
};
})
(mkIf amCfg.enable {
networking.firewall.allowedTCPPorts = optional amCfg.openFirewall amCfg.port;
systemd.services."alertmanager${amVersion}" = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
${amCfg.package}/bin/alertmanager \
${concatStringsSep " \\\n " cmdlineArgs}
'';
serviceConfig = {
User = amCfg.user;
Group = amCfg.group;
Restart = "always";
PrivateTmp = true;
WorkingDirectory = "/tmp";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
};
};
})
];
in {
options = {
services.prometheus.alertmanager = amOptions;
services.prometheus2.alertmanager = amOptions;
}; };
config = mkMerge [ config = mkMerge [
(mkIf cfg.enable { (mkAMConfig cfg "")
assertions = singleton { (mkAMConfig cfg2 "2")
assertion = cfg.configuration != null || cfg.configText != null;
message = "Can not enable alertmanager without a configuration. "
+ "Set either the `configuration` or `configText` attribute.";
};
})
(mkIf cfg.enable {
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
systemd.services.alertmanager = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
${cfg.package}/bin/alertmanager \
${concatStringsSep " \\\n " cmdlineArgs}
'';
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Restart = "always";
PrivateTmp = true;
WorkingDirectory = "/tmp";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
};
};
})
]; ];
} }

View File

@ -4,8 +4,11 @@ with lib;
let let
cfg = config.services.prometheus; cfg = config.services.prometheus;
cfg2 = config.services.prometheus2;
promUser = "prometheus"; promUser = "prometheus";
promGroup = "prometheus"; promGroup = "prometheus";
prom2User = "prometheus2";
prom2Group = "prometheus2";
# Get a submodule without any embedded metadata: # Get a submodule without any embedded metadata:
_filter = x: filterAttrs (k: v: k != "_module") x; _filter = x: filterAttrs (k: v: k != "_module") x;
@ -17,13 +20,21 @@ let
promtool ${what} $out promtool ${what} $out
''; '';
# a wrapper that verifies that the configuration is valid for
# prometheus 2
prom2toolCheck = what: name: file: pkgs.runCommand "${name}-${what}-checked"
{ buildInputs = [ cfg2.package ]; } ''
ln -s ${file} $out
promtool ${what} $out
'';
# Pretty-print JSON to a file # Pretty-print JSON to a file
writePrettyJSON = name: x: writePrettyJSON = name: x:
pkgs.runCommand name { preferLocalBuild = true; } '' pkgs.runCommand name { preferLocalBuild = true; } ''
echo '${builtins.toJSON x}' | ${pkgs.jq}/bin/jq . > $out echo '${builtins.toJSON x}' | ${pkgs.jq}/bin/jq . > $out
''; '';
# This becomes the main config file # This becomes the main config file for Prometheus 1
promConfig = { promConfig = {
global = cfg.globalConfig; global = cfg.globalConfig;
rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [ rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [
@ -35,7 +46,7 @@ let
generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig; generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig;
prometheusYml = let prometheusYml = let
yml = if cfg.configText != null then yml = if cfg.configText != null then
pkgs.writeText "prometheus.yml" cfg.configText pkgs.writeText "prometheus.yml" cfg.configText
else generatedPrometheusYml; else generatedPrometheusYml;
in promtoolCheck "check-config" "prometheus.yml" yml; in promtoolCheck "check-config" "prometheus.yml" yml;
@ -50,6 +61,39 @@ let
(optionalString (cfg.webExternalUrl != null) "-web.external-url=${cfg.webExternalUrl}") (optionalString (cfg.webExternalUrl != null) "-web.external-url=${cfg.webExternalUrl}")
]; ];
# This becomes the main config file for Prometheus 2
promConfig2 = {
global = cfg2.globalConfig;
rule_files = map (prom2toolCheck "check-rules" "rules") (cfg2.ruleFiles ++ [
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg2.rules))
]);
scrape_configs = cfg2.scrapeConfigs;
alerting = optionalAttrs (cfg2.alertmanagerURL != []) {
alertmanagers = [{
static_configs = [{
targets = cfg2.alertmanagerURL;
}];
}];
};
};
generatedPrometheus2Yml = writePrettyJSON "prometheus.yml" promConfig2;
prometheus2Yml = let
yml = if cfg2.configText != null then
pkgs.writeText "prometheus.yml" cfg2.configText
else generatedPrometheus2Yml;
in promtoo2lCheck "check-config" "prometheus.yml" yml;
cmdlineArgs2 = cfg2.extraFlags ++ [
"--storage.tsdb.path=${cfg2.dataDir}/data/"
"--config.file=${prometheus2Yml}"
"--web.listen-address=${cfg2.listenAddress}"
"--alertmanager.notification-queue-capacity=${toString cfg2.alertmanagerNotificationQueueCapacity}"
"--alertmanager.timeout=${toString cfg2.alertmanagerTimeout}s"
(optionalString (cfg2.webExternalUrl != null) "-web.external-url=${cfg2.webExternalUrl}")
];
promTypes.globalConfig = types.submodule { promTypes.globalConfig = types.submodule {
options = { options = {
scrape_interval = mkOption { scrape_interval = mkOption {
@ -497,30 +541,178 @@ in {
''; '';
}; };
}; };
}; services.prometheus2 = {
config = mkIf cfg.enable { enable = mkOption {
users.groups.${promGroup}.gid = config.ids.gids.prometheus; type = types.bool;
users.users.${promUser} = { default = false;
description = "Prometheus daemon user"; description = ''
uid = config.ids.uids.prometheus; Enable the Prometheus 2 monitoring daemon.
group = promGroup; '';
home = cfg.dataDir; };
createHome = true;
}; package = mkOption {
systemd.services.prometheus = { type = types.package;
wantedBy = [ "multi-user.target" ]; default = pkgs.prometheus_2;
after = [ "network.target" ]; defaultText = "pkgs.prometheus_2";
script = '' description = ''
#!/bin/sh The prometheus2 package that should be used.
exec ${cfg.package}/bin/prometheus \ '';
${concatStringsSep " \\\n " cmdlineArgs} };
'';
serviceConfig = { listenAddress = mkOption {
User = promUser; type = types.str;
Restart = "always"; default = "0.0.0.0:9090";
WorkingDirectory = cfg.dataDir; description = ''
Address to listen on for the web interface, API, and telemetry.
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/prometheus2";
description = ''
Directory to store Prometheus 2 metrics data.
'';
};
extraFlags = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Extra commandline options when launching Prometheus 2.
'';
};
configText = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
If non-null, this option defines the text that is written to
prometheus.yml. If null, the contents of prometheus.yml is generated
from the structured config options.
'';
};
globalConfig = mkOption {
type = promTypes.globalConfig;
default = {};
apply = _filter;
description = ''
Parameters that are valid in all configuration contexts. They
also serve as defaults for other configuration sections
'';
};
rules = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Alerting and/or Recording rules to evaluate at runtime.
'';
};
ruleFiles = mkOption {
type = types.listOf types.path;
default = [];
description = ''
Any additional rules files to include in this configuration.
'';
};
scrapeConfigs = mkOption {
type = types.listOf promTypes.scrape_config;
default = [];
apply = x: map _filter x;
description = ''
A list of scrape configurations.
'';
};
alertmanagerURL = mkOption {
type = types.listOf types.str;
default = [];
description = ''
List of Alertmanager URLs to send notifications to.
'';
};
alertmanagerNotificationQueueCapacity = mkOption {
type = types.int;
default = 10000;
description = ''
The capacity of the queue for pending alert manager notifications.
'';
};
alertmanagerTimeout = mkOption {
type = types.int;
default = 10;
description = ''
Alert manager HTTP API timeout (in seconds).
'';
};
webExternalUrl = mkOption {
type = types.nullOr types.str;
default = null;
example = "https://example.com/";
description = ''
The URL under which Prometheus is externally reachable (for example,
if Prometheus is served via a reverse proxy).
'';
}; };
}; };
}; };
config = mkMerge [
(mkIf cfg.enable {
users.groups.${promGroup}.gid = config.ids.gids.prometheus;
users.users.${promUser} = {
description = "Prometheus daemon user";
uid = config.ids.uids.prometheus;
group = promGroup;
home = cfg.dataDir;
createHome = true;
};
systemd.services.prometheus = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
#!/bin/sh
exec ${cfg.package}/bin/prometheus \
${concatStringsSep " \\\n " cmdlineArgs}
'';
serviceConfig = {
User = promUser;
Restart = "always";
WorkingDirectory = cfg.dataDir;
};
};
})
(mkIf cfg2.enable {
users.groups.${prom2Group}.gid = config.ids.gids.prometheus2;
users.users.${prom2User} = {
description = "Prometheus2 daemon user";
uid = config.ids.uids.prometheus2;
group = prom2Group;
home = cfg2.dataDir;
createHome = true;
};
systemd.services.prometheus2 = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
#!/bin/sh
exec ${cfg.package}/bin/prometheus \
${concatStringsSep " \\\n " cmdlineArgs2}
'';
serviceConfig = {
User = prom2User;
Restart = "always";
WorkingDirectory = cfg2.dataDir;
};
};
})
];
} }

View File

@ -4,8 +4,10 @@ with lib;
let let
cfg = config.services.prometheus.exporters; cfg = config.services.prometheus.exporters;
cfg2 = config.services.prometheus2.exporters;
# each attribute in `exporterOpts` is expected to have specified: # each attribute in `exporterOpts` is a function that when executed
# with `cfg` or `cfg2` as parameter is expected to have specified:
# - port (types.int): port on which the exporter listens # - port (types.int): port on which the exporter listens
# - serviceOpts (types.attrs): config that is merged with the # - serviceOpts (types.attrs): config that is merged with the
# default definition of the exporter's # default definition of the exporter's
@ -108,13 +110,18 @@ let
}; };
}; };
mkSubModules = (foldl' (a: b: a//b) {} mkSubModules = exCfg:
(mapAttrsToList (name: opts: mkSubModule { (foldl' (a: b: a//b) {}
inherit name; (mapAttrsToList (name: confGen:
inherit (opts) port serviceOpts; let
extraOpts = opts.extraOpts or {}; conf = (confGen exCfg);
}) exporterOpts) in
); mkSubModule {
inherit name;
inherit (conf) port serviceOpts;
extraOpts = conf.extraOpts or {};
}) exporterOpts)
);
mkExporterConf = { name, conf, serviceOpts }: mkExporterConf = { name, conf, serviceOpts }:
mkIf conf.enable { mkIf conf.enable {
@ -133,11 +140,36 @@ let
serviceConfig.Group = conf.group; serviceConfig.Group = conf.group;
}); });
}; };
mkExportersConfig = exCfg: promVersion:
([{
assertions = [{
assertion = (exCfg.snmp.configurationPath == null) != (exCfg.snmp.configuration == null);
message = ''
Please ensure you have either `services.prometheus.exporters.snmp.configuration'
or `services.prometheus${promVersion}.exporters.snmp.configurationPath' set!
'';
}];
}] ++ [(mkIf config.services.minio.enable {
services."prometheus${promVersion}".exporters.minio = {
minioAddress = mkDefault "http://localhost:9000";
minioAccessKey = mkDefault config.services.minio.accessKey;
minioAccessSecret = mkDefault config.services.minio.secretKey;
};
})] ++ (mapAttrsToList (name: confGen:
let
conf = (confGen exCfg);
in
mkExporterConf {
inherit name;
inherit (conf) serviceOpts;
conf = exCfg.${name};
}) exporterOpts)
);
in in
{ {
options.services.prometheus.exporters = mkOption { options.services.prometheus.exporters = mkOption {
type = types.submodule { type = types.submodule {
options = (mkSubModules); options = (mkSubModules cfg);
}; };
description = "Prometheus exporter configuration"; description = "Prometheus exporter configuration";
default = {}; default = {};
@ -152,25 +184,24 @@ in
''; '';
}; };
config = mkMerge ([{ options.services.prometheus2.exporters = mkOption {
assertions = [{ type = types.submodule {
assertion = (cfg.snmp.configurationPath == null) != (cfg.snmp.configuration == null); options = (mkSubModules cfg2);
message = '' };
Please ensure you have either `services.prometheus.exporters.snmp.configuration' description = "Prometheus 2 exporter configuration";
or `services.prometheus.exporters.snmp.configurationPath' set! default = {};
''; example = literalExample ''
}]; {
}] ++ [(mkIf config.services.minio.enable { node = {
services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000"; enable = true;
services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey; enabledCollectors = [ "systemd" ];
services.prometheus.exporters.minio.minioAccessSecret = mkDefault config.services.minio.secretKey; };
})] ++ (mapAttrsToList (name: conf: varnish.enable = true;
mkExporterConf { }
inherit name; '';
inherit (conf) serviceOpts; };
conf = cfg.${name};
}) exporterOpts) config = mkMerge ((mkExportersConfig cfg "") ++ (mkExportersConfig cfg2 "2"));
);
meta = { meta = {
doc = ./exporters.xml; doc = ./exporters.xml;

View File

@ -2,54 +2,55 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.bind; let
in cfg = baseCfg.bind;
{ in
port = 9119; {
extraOpts = { port = 9119;
bindURI = mkOption { extraOpts = {
type = types.str; bindURI = mkOption {
default = "http://localhost:8053/"; type = types.str;
description = '' default = "http://localhost:8053/";
HTTP XML API address of an Bind server. description = ''
''; HTTP XML API address of an Bind server.
'';
};
bindTimeout = mkOption {
type = types.str;
default = "10s";
description = ''
Timeout for trying to get stats from Bind.
'';
};
bindVersion = mkOption {
type = types.enum [ "xml.v2" "xml.v3" "auto" ];
default = "auto";
description = ''
BIND statistics version. Can be detected automatically.
'';
};
bindGroups = mkOption {
type = types.listOf (types.enum [ "server" "view" "tasks" ]);
default = [ "server" "view" ];
description = ''
List of statistics to collect. Available: [server, view, tasks]
'';
};
}; };
bindTimeout = mkOption { serviceOpts = {
type = types.str; serviceConfig = {
default = "10s"; DynamicUser = true;
description = '' ExecStart = ''
Timeout for trying to get stats from Bind. ${pkgs.prometheus-bind-exporter}/bin/bind_exporter \
''; -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
-bind.pid-file /var/run/named/named.pid \
-bind.timeout ${toString cfg.bindTimeout} \
-bind.stats-url ${cfg.bindURI} \
-bind.stats-version ${cfg.bindVersion} \
-bind.stats-groups ${concatStringsSep "," cfg.bindGroups} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
bindVersion = mkOption { }
type = types.enum [ "xml.v2" "xml.v3" "auto" ];
default = "auto";
description = ''
BIND statistics version. Can be detected automatically.
'';
};
bindGroups = mkOption {
type = types.listOf (types.enum [ "server" "view" "tasks" ]);
default = [ "server" "view" ];
description = ''
List of statistics to collect. Available: [server, view, tasks]
'';
};
};
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-bind-exporter}/bin/bind_exporter \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
-bind.pid-file /var/run/named/named.pid \
-bind.timeout ${toString cfg.bindTimeout} \
-bind.stats-url ${cfg.bindURI} \
-bind.stats-version ${cfg.bindVersion} \
-bind.stats-groups ${concatStringsSep "," cfg.bindGroups} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,30 +2,31 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.blackbox; let
in cfg = baseCfg.blackbox;
{ in
port = 9115; {
extraOpts = { port = 9115;
configFile = mkOption { extraOpts = {
type = types.path; configFile = mkOption {
description = '' type = types.path;
Path to configuration file. description = ''
''; Path to configuration file.
'';
};
}; };
}; serviceOpts = {
serviceOpts = { serviceConfig = {
serviceConfig = { AmbientCapabilities = [ "CAP_NET_RAW" ]; # for ping probes
AmbientCapabilities = [ "CAP_NET_RAW" ]; # for ping probes DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \
${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --config.file ${cfg.configFile} \
--config.file ${cfg.configFile} \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; };
}; };
}; }
}

View File

@ -2,77 +2,78 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.collectd; let
in cfg = baseCfg.collectd;
{ in
port = 9103; {
extraOpts = { port = 9103;
collectdBinary = { extraOpts = {
enable = mkEnableOption "collectd binary protocol receiver"; collectdBinary = {
enable = mkEnableOption "collectd binary protocol receiver";
authFile = mkOption { authFile = mkOption {
default = null; default = null;
type = types.nullOr types.path; type = types.nullOr types.path;
description = "File mapping user names to pre-shared keys (passwords)."; description = "File mapping user names to pre-shared keys (passwords).";
}; };
port = mkOption { port = mkOption {
type = types.int; type = types.int;
default = 25826; default = 25826;
description = ''Network address on which to accept collectd binary network packets.''; description = ''Network address on which to accept collectd binary network packets.'';
}; };
listenAddress = mkOption { listenAddress = mkOption {
type = types.str; type = types.str;
default = "0.0.0.0"; default = "0.0.0.0";
description = '' description = ''
Address to listen on for binary network packets. Address to listen on for binary network packets.
'';
};
securityLevel = mkOption {
type = types.enum ["None" "Sign" "Encrypt"];
default = "None";
description = ''
Minimum required security level for accepted packets.
''; '';
};
}; };
securityLevel = mkOption { logFormat = mkOption {
type = types.enum ["None" "Sign" "Encrypt"]; type = types.str;
default = "None"; default = "logger:stderr";
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true";
description = '' description = ''
Minimum required security level for accepted packets. Set the log target and format.
'';
};
logLevel = mkOption {
type = types.enum ["debug" "info" "warn" "error" "fatal"];
default = "info";
description = ''
Only log messages with the given severity or above.
''; '';
}; };
}; };
serviceOpts = let
logFormat = mkOption { collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
type = types.str; -collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
default = "logger:stderr"; -collectd.security-level ${cfg.collectdBinary.securityLevel} \
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true"; '' else "";
description = '' in {
Set the log target and format. serviceConfig = {
''; DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
-log.format ${cfg.logFormat} \
-log.level ${cfg.logLevel} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${collectSettingsArgs} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
}
logLevel = mkOption {
type = types.enum ["debug" "info" "warn" "error" "fatal"];
default = "info";
description = ''
Only log messages with the given severity or above.
'';
};
};
serviceOpts = let
collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
-collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
-collectd.security-level ${cfg.collectdBinary.securityLevel} \
'' else "";
in {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
-log.format ${cfg.logFormat} \
-log.level ${cfg.logLevel} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${collectSettingsArgs} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,38 +2,39 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.dnsmasq; let
in cfg = baseCfg.dnsmasq;
{ in
port = 9153; {
extraOpts = { port = 9153;
dnsmasqListenAddress = mkOption { extraOpts = {
type = types.str; dnsmasqListenAddress = mkOption {
default = "localhost:53"; type = types.str;
description = '' default = "localhost:53";
Address on which dnsmasq listens. description = ''
''; Address on which dnsmasq listens.
'';
};
leasesPath = mkOption {
type = types.path;
default = "/var/lib/misc/dnsmasq.leases";
example = "/var/lib/dnsmasq/dnsmasq.leases";
description = ''
Path to the <literal>dnsmasq.leases</literal> file.
'';
};
}; };
leasesPath = mkOption { serviceOpts = {
type = types.path; serviceConfig = {
default = "/var/lib/misc/dnsmasq.leases"; DynamicUser = true;
example = "/var/lib/dnsmasq/dnsmasq.leases"; ExecStart = ''
description = '' ${pkgs.prometheus-dnsmasq-exporter}/bin/dnsmasq_exporter \
Path to the <literal>dnsmasq.leases</literal> file. --listen ${cfg.listenAddress}:${toString cfg.port} \
''; --dnsmasq ${cfg.dnsmasqListenAddress} \
--leases_path ${cfg.leasesPath} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
}; }
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-dnsmasq-exporter}/bin/dnsmasq_exporter \
--listen ${cfg.listenAddress}:${toString cfg.port} \
--dnsmasq ${cfg.dnsmasqListenAddress} \
--leases_path ${cfg.leasesPath} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,71 +2,72 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.dovecot; let
in cfg = baseCfg.dovecot;
{ in
port = 9166; {
extraOpts = { port = 9166;
telemetryPath = mkOption { extraOpts = {
type = types.str; telemetryPath = mkOption {
default = "/metrics"; type = types.str;
description = '' default = "/metrics";
Path under which to expose metrics. description = ''
''; Path under which to expose metrics.
}; '';
socketPath = mkOption { };
type = types.path; socketPath = mkOption {
default = "/var/run/dovecot/stats"; type = types.path;
example = "/var/run/dovecot2/old-stats"; default = "/var/run/dovecot/stats";
description = '' example = "/var/run/dovecot2/old-stats";
Path under which the stats socket is placed. description = ''
The user/group under which the exporter runs, Path under which the stats socket is placed.
should be able to access the socket in order The user/group under which the exporter runs,
to scrape the metrics successfully. should be able to access the socket in order
to scrape the metrics successfully.
Please keep in mind that the stats module has changed in Please keep in mind that the stats module has changed in
<link xlink:href="https://wiki2.dovecot.org/Upgrading/2.3">Dovecot 2.3+</link> which <link xlink:href="https://wiki2.dovecot.org/Upgrading/2.3">Dovecot 2.3+</link> which
is not <link xlink:href="https://github.com/kumina/dovecot_exporter/issues/8">compatible with this exporter</link>. is not <link xlink:href="https://github.com/kumina/dovecot_exporter/issues/8">compatible with this exporter</link>.
The following extra config has to be passed to Dovecot to ensure that recent versions The following extra config has to be passed to Dovecot to ensure that recent versions
work with this exporter: work with this exporter:
<programlisting> <programlisting>
{ {
<xref linkend="opt-services.prometheus.exporters.dovecot.enable" /> = true; <xref linkend="opt-services.prometheus.exporters.dovecot.enable" /> = true;
<xref linkend="opt-services.prometheus.exporters.dovecot.socketPath" /> = "/var/run/dovecot2/old-stats"; <xref linkend="opt-services.prometheus.exporters.dovecot.socketPath" /> = "/var/run/dovecot2/old-stats";
<xref linkend="opt-services.dovecot2.extraConfig" /> = ''' <xref linkend="opt-services.dovecot2.extraConfig" /> = '''
mail_plugins = $mail_plugins old_stats mail_plugins = $mail_plugins old_stats
service old-stats { service old-stats {
unix_listener old-stats { unix_listener old-stats {
user = nobody user = nobody
group = nobody group = nobody
}
} }
} ''';
'''; }
} </programlisting>
</programlisting> '';
''; };
scopes = mkOption {
type = types.listOf types.str;
default = [ "user" ];
example = [ "user" "global" ];
description = ''
Stats scopes to query.
'';
};
}; };
scopes = mkOption { serviceOpts = {
type = types.listOf types.str; serviceConfig = {
default = [ "user" ]; ExecStart = ''
example = [ "user" "global" ]; ${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \
description = '' --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
Stats scopes to query. --web.telemetry-path ${cfg.telemetryPath} \
''; --dovecot.socket-path ${cfg.socketPath} \
--dovecot.scopes ${concatStringsSep "," cfg.scopes} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
}; }
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--dovecot.socket-path ${cfg.socketPath} \
--dovecot.scopes ${concatStringsSep "," cfg.scopes} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,38 +2,39 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.fritzbox; let
in cfg = baseCfg.fritzbox;
{ in
port = 9133; {
extraOpts = { port = 9133;
gatewayAddress = mkOption { extraOpts = {
type = types.str; gatewayAddress = mkOption {
default = "fritz.box"; type = types.str;
description = '' default = "fritz.box";
The hostname or IP of the FRITZ!Box. description = ''
''; The hostname or IP of the FRITZ!Box.
}; '';
};
gatewayPort = mkOption { gatewayPort = mkOption {
type = types.int; type = types.int;
default = 49000; default = 49000;
description = '' description = ''
The port of the FRITZ!Box UPnP service. The port of the FRITZ!Box UPnP service.
''; '';
};
}; };
}; serviceOpts = {
serviceOpts = { serviceConfig = {
serviceConfig = { DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-fritzbox-exporter}/bin/fritzbox_exporter \
${pkgs.prometheus-fritzbox-exporter}/bin/fritzbox_exporter \ -listen-address ${cfg.listenAddress}:${toString cfg.port} \
-listen-address ${cfg.listenAddress}:${toString cfg.port} \ -gateway-address ${cfg.gatewayAddress} \
-gateway-address ${cfg.gatewayAddress} \ -gateway-port ${toString cfg.gatewayPort} \
-gateway-port ${toString cfg.gatewayPort} \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; };
}; };
}; }
}

View File

@ -2,35 +2,36 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.json; let
in cfg = baseCfg.json;
{ in
port = 7979; {
extraOpts = { port = 7979;
url = mkOption { extraOpts = {
type = types.str; url = mkOption {
description = '' type = types.str;
URL to scrape JSON from. description = ''
''; URL to scrape JSON from.
'';
};
configFile = mkOption {
type = types.path;
description = ''
Path to configuration file.
'';
};
listenAddress = {}; # not used
}; };
configFile = mkOption { serviceOpts = {
type = types.path; serviceConfig = {
description = '' DynamicUser = true;
Path to configuration file. ExecStart = ''
''; ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
--port ${toString cfg.port} \
${cfg.url} ${cfg.configFile} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
listenAddress = {}; # not used }
};
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
--port ${toString cfg.port} \
${cfg.url} ${cfg.configFile} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,64 +2,65 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.minio; let
in cfg = baseCfg.minio;
{ in
port = 9290; {
extraOpts = { port = 9290;
minioAddress = mkOption { extraOpts = {
type = types.str; minioAddress = mkOption {
example = "https://10.0.0.1:9000"; type = types.str;
description = '' example = "https://10.0.0.1:9000";
The URL of the minio server. description = ''
Use HTTPS if Minio accepts secure connections only. The URL of the minio server.
By default this connects to the local minio server if enabled. Use HTTPS if Minio accepts secure connections only.
''; By default this connects to the local minio server if enabled.
}; '';
};
minioAccessKey = mkOption { minioAccessKey = mkOption {
type = types.str; type = types.str;
example = "yourMinioAccessKey"; example = "yourMinioAccessKey";
description = '' description = ''
The value of the Minio access key. The value of the Minio access key.
It is required in order to connect to the server. It is required in order to connect to the server.
By default this uses the one from the local minio server if enabled By default this uses the one from the local minio server if enabled
and <literal>config.services.minio.accessKey</literal>. and <literal>config.services.minio.accessKey</literal>.
''; '';
}; };
minioAccessSecret = mkOption { minioAccessSecret = mkOption {
type = types.str; type = types.str;
description = '' description = ''
The value of the Minio access secret. The value of the Minio access secret.
It is required in order to connect to the server. It is required in order to connect to the server.
By default this uses the one from the local minio server if enabled By default this uses the one from the local minio server if enabled
and <literal>config.services.minio.secretKey</literal>. and <literal>config.services.minio.secretKey</literal>.
''; '';
}; };
minioBucketStats = mkOption { minioBucketStats = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
Collect statistics about the buckets and files in buckets. Collect statistics about the buckets and files in buckets.
It requires more computation, use it carefully in case of large buckets.. It requires more computation, use it carefully in case of large buckets..
''; '';
};
}; };
}; serviceOpts = {
serviceOpts = { serviceConfig = {
serviceConfig = { DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-minio-exporter}/bin/minio-exporter \
${pkgs.prometheus-minio-exporter}/bin/minio-exporter \ -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ -minio.server ${cfg.minioAddress} \
-minio.server ${cfg.minioAddress} \ -minio.access-key ${cfg.minioAccessKey} \
-minio.access-key ${cfg.minioAccessKey} \ -minio.access-secret ${cfg.minioAccessSecret} \
-minio.access-secret ${cfg.minioAccessSecret} \ ${optionalString cfg.minioBucketStats "-minio.bucket-stats"} \
${optionalString cfg.minioBucketStats "-minio.bucket-stats"} \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; };
}; };
}; }
}

View File

@ -2,46 +2,47 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.nginx; let
in cfg = baseCfg.nginx;
{ in
port = 9113; {
extraOpts = { port = 9113;
scrapeUri = mkOption { extraOpts = {
type = types.str; scrapeUri = mkOption {
default = "http://localhost/nginx_status"; type = types.str;
description = '' default = "http://localhost/nginx_status";
Address to access the nginx status page. description = ''
Can be enabled with services.nginx.statusPage = true. Address to access the nginx status page.
''; Can be enabled with services.nginx.statusPage = true.
'';
};
telemetryEndpoint = mkOption {
type = types.str;
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
insecure = mkOption {
type = types.bool;
default = true;
description = ''
Ignore server certificate if using https.
'';
};
}; };
telemetryEndpoint = mkOption { serviceOpts = {
type = types.str; serviceConfig = {
default = "/metrics"; DynamicUser = true;
description = '' ExecStart = ''
Path under which to expose metrics. ${pkgs.prometheus-nginx-exporter}/bin/nginx_exporter \
''; --nginx.scrape_uri '${cfg.scrapeUri}' \
--telemetry.address ${cfg.listenAddress}:${toString cfg.port} \
--telemetry.endpoint ${cfg.telemetryEndpoint} \
--insecure ${toString cfg.insecure} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
insecure = mkOption { }
type = types.bool;
default = true;
description = ''
Ignore server certificate if using https.
'';
};
};
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-nginx-exporter}/bin/nginx_exporter \
--nginx.scrape_uri '${cfg.scrapeUri}' \
--telemetry.address ${cfg.listenAddress}:${toString cfg.port} \
--telemetry.endpoint ${cfg.telemetryEndpoint} \
--insecure ${toString cfg.insecure} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,39 +2,40 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.node; let
in cfg = baseCfg.node;
{ in
port = 9100; {
extraOpts = { port = 9100;
enabledCollectors = mkOption { extraOpts = {
type = types.listOf types.string; enabledCollectors = mkOption {
default = []; type = types.listOf types.string;
example = ''[ "systemd" ]''; default = [];
description = '' example = ''[ "systemd" ]'';
Collectors to enable. The collectors listed here are enabled in addition to the default ones. description = ''
''; Collectors to enable. The collectors listed here are enabled in addition to the default ones.
'';
};
disabledCollectors = mkOption {
type = types.listOf types.str;
default = [];
example = ''[ "timex" ]'';
description = ''
Collectors to disable which are enabled by default.
'';
};
}; };
disabledCollectors = mkOption { serviceOpts = {
type = types.listOf types.str; serviceConfig = {
default = []; RuntimeDirectory = "prometheus-node-exporter";
example = ''[ "timex" ]''; ExecStart = ''
description = '' ${pkgs.prometheus-node-exporter}/bin/node_exporter \
Collectors to disable which are enabled by default. ${concatMapStringsSep " " (x: "--collector." + x) cfg.enabledCollectors} \
''; ${concatMapStringsSep " " (x: "--no-collector." + x) cfg.disabledCollectors} \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
}; };
}; }
serviceOpts = {
serviceConfig = {
RuntimeDirectory = "prometheus-node-exporter";
ExecStart = ''
${pkgs.prometheus-node-exporter}/bin/node_exporter \
${concatMapStringsSep " " (x: "--collector." + x) cfg.enabledCollectors} \
${concatMapStringsSep " " (x: "--no-collector." + x) cfg.disabledCollectors} \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View File

@ -2,80 +2,81 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.postfix; let
in cfg = baseCfg.postfix;
{ in
port = 9154; {
extraOpts = { port = 9154;
telemetryPath = mkOption { extraOpts = {
type = types.str; telemetryPath = mkOption {
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
logfilePath = mkOption {
type = types.path;
default = "/var/log/postfix_exporter_input.log";
example = "/var/log/mail.log";
description = ''
Path where Postfix writes log entries.
This file will be truncated by this exporter!
'';
};
showqPath = mkOption {
type = types.path;
default = "/var/spool/postfix/public/showq";
example = "/var/lib/postfix/queue/public/showq";
description = ''
Path where Postfix places it's showq socket.
'';
};
systemd = {
enable = mkEnableOption ''
reading metrics from the systemd-journal instead of from a logfile
'';
unit = mkOption {
type = types.str; type = types.str;
default = "postfix.service"; default = "/metrics";
description = '' description = ''
Name of the postfix systemd unit. Path under which to expose metrics.
''; '';
}; };
slice = mkOption { logfilePath = mkOption {
type = types.nullOr types.str; type = types.path;
default = null; default = "/var/log/postfix_exporter_input.log";
example = "/var/log/mail.log";
description = '' description = ''
Name of the postfix systemd slice. Path where Postfix writes log entries.
This overrides the <option>systemd.unit</option>. This file will be truncated by this exporter!
''; '';
}; };
journalPath = mkOption { showqPath = mkOption {
type = types.nullOr types.path; type = types.path;
default = null; default = "/var/spool/postfix/public/showq";
example = "/var/lib/postfix/queue/public/showq";
description = '' description = ''
Path to the systemd journal. Path where Postfix places it's showq socket.
'';
};
systemd = {
enable = mkEnableOption ''
reading metrics from the systemd-journal instead of from a logfile
'';
unit = mkOption {
type = types.str;
default = "postfix.service";
description = ''
Name of the postfix systemd unit.
'';
};
slice = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Name of the postfix systemd slice.
This overrides the <option>systemd.unit</option>.
'';
};
journalPath = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
Path to the systemd journal.
'';
};
};
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--postfix.showq_path ${cfg.showqPath} \
${concatStringsSep " \\\n " (cfg.extraFlags
++ optional cfg.systemd.enable "--systemd.enable"
++ optional cfg.systemd.enable (if cfg.systemd.slice != null
then "--systemd.slice ${cfg.systemd.slice}"
else "--systemd.unit ${cfg.systemd.unit}")
++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null))
"--systemd.jounal_path ${cfg.systemd.journalPath}"
++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${cfg.logfilePath}")}
''; '';
}; };
}; };
}; }
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--postfix.showq_path ${cfg.showqPath} \
${concatStringsSep " \\\n " (cfg.extraFlags
++ optional cfg.systemd.enable "--systemd.enable"
++ optional cfg.systemd.enable (if cfg.systemd.slice != null
then "--systemd.slice ${cfg.systemd.slice}"
else "--systemd.unit ${cfg.systemd.unit}")
++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null))
"--systemd.jounal_path ${cfg.systemd.journalPath}"
++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${cfg.logfilePath}")}
'';
};
};
}

View File

@ -2,70 +2,71 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.snmp; let
in cfg = baseCfg.snmp;
{ in
port = 9116; {
extraOpts = { port = 9116;
configurationPath = mkOption { extraOpts = {
type = types.nullOr types.path; configurationPath = mkOption {
default = null; type = types.nullOr types.path;
description = '' default = null;
Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option. description = ''
''; Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option.
example = "./snmp.yml"; '';
}; example = "./snmp.yml";
};
configuration = mkOption { configuration = mkOption {
type = types.nullOr types.attrs; type = types.nullOr types.attrs;
default = {}; default = {};
description = '' description = ''
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option. Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
''; '';
example = '' example = ''
{ {
"default" = { "default" = {
"version" = 2; "version" = 2;
"auth" = { "auth" = {
"community" = "public"; "community" = "public";
};
}; };
}; };
}; '';
''; };
};
logFormat = mkOption { logFormat = mkOption {
type = types.str; type = types.str;
default = "logger:stderr"; default = "logger:stderr";
description = '' description = ''
Set the log target and format. Set the log target and format.
''; '';
}; };
logLevel = mkOption { logLevel = mkOption {
type = types.enum ["debug" "info" "warn" "error" "fatal"]; type = types.enum ["debug" "info" "warn" "error" "fatal"];
default = "info"; default = "info";
description = '' description = ''
Only log messages with the given severity or above. Only log messages with the given severity or above.
''; '';
};
}; };
}; serviceOpts = let
serviceOpts = let configFile = if cfg.configurationPath != null
configFile = if cfg.configurationPath != null then cfg.configurationPath
then cfg.configurationPath else "${pkgs.writeText "snmp-eporter-conf.yml" (builtins.toJSON cfg.configuration)}";
else "${pkgs.writeText "snmp-eporter-conf.yml" (builtins.toJSON cfg.configuration)}"; in {
in { serviceConfig = {
serviceConfig = { DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \
${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \ --config.file ${configFile} \
--config.file=${configFile} \ --log.format ${cfg.logFormat} \
--log.format=${cfg.logFormat} \ --log.level ${cfg.logLevel} \
--log.level=${cfg.logLevel} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.listen-address=${cfg.listenAddress}:${toString cfg.port} \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; };
}; };
}; }
}

View File

@ -2,31 +2,32 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.surfboard; let
in cfg = baseCfg.surfboard;
{ in
port = 9239; {
extraOpts = { port = 9239;
modemAddress = mkOption { extraOpts = {
type = types.str; modemAddress = mkOption {
default = "192.168.100.1"; type = types.str;
description = '' default = "192.168.100.1";
The hostname or IP of the cable modem. description = ''
''; The hostname or IP of the cable modem.
'';
};
}; };
}; serviceOpts = {
serviceOpts = { description = "Prometheus exporter for surfboard cable modem";
description = "Prometheus exporter for surfboard cable modem"; unitConfig.Documentation = "https://github.com/ipstatic/surfboard_exporter";
unitConfig.Documentation = "https://github.com/ipstatic/surfboard_exporter"; serviceConfig = {
serviceConfig = { DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-surfboard-exporter}/bin/surfboard_exporter \
${pkgs.prometheus-surfboard-exporter}/bin/surfboard_exporter \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --modem-address ${cfg.modemAddress} \
--modem-address ${cfg.modemAddress} \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; };
}; };
}; }
}

View File

@ -2,44 +2,45 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.tor; let
in cfg = baseCfg.tor;
{ in
port = 9130; {
extraOpts = { port = 9130;
torControlAddress = mkOption { extraOpts = {
type = types.str; torControlAddress = mkOption {
default = "127.0.0.1"; type = types.str;
description = '' default = "127.0.0.1";
Tor control IP address or hostname. description = ''
''; Tor control IP address or hostname.
}; '';
};
torControlPort = mkOption { torControlPort = mkOption {
type = types.int; type = types.int;
default = 9051; default = 9051;
description = '' description = ''
Tor control port. Tor control port.
''; '';
}; };
};
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-tor-exporter}/bin/prometheus-tor-exporter \
-b ${cfg.listenAddress} \
-p ${toString cfg.port} \
-a ${cfg.torControlAddress} \
-c ${toString cfg.torControlPort} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
}; };
serviceOpts = {
serviceConfig = {
DynamicUser = true;
ExecStart = ''
${pkgs.prometheus-tor-exporter}/bin/prometheus-tor-exporter \
-b ${cfg.listenAddress} \
-p ${toString cfg.port} \
-a ${cfg.torControlAddress} \
-c ${toString cfg.torControlPort} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
# CPython requires a process to either have $HOME defined or run as a UID # CPython requires a process to either have $HOME defined or run as a UID
# defined in /etc/passwd. The latter is false with DynamicUser, so define a # defined in /etc/passwd. The latter is false with DynamicUser, so define a
# dummy $HOME. https://bugs.python.org/issue10496 # dummy $HOME. https://bugs.python.org/issue10496
environment = { HOME = "/var/empty"; }; environment = { HOME = "/var/empty"; };
}; };
} }

View File

@ -2,66 +2,67 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.unifi; let
in cfg = baseCfg.unifi;
{ in
port = 9130; {
extraOpts = { port = 9130;
unifiAddress = mkOption { extraOpts = {
type = types.str; unifiAddress = mkOption {
example = "https://10.0.0.1:8443"; type = types.str;
description = '' example = "https://10.0.0.1:8443";
URL of the UniFi Controller API. description = ''
''; URL of the UniFi Controller API.
}; '';
};
unifiInsecure = mkOption { unifiInsecure = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
If enabled skip the verification of the TLS certificate of the UniFi Controller API. If enabled skip the verification of the TLS certificate of the UniFi Controller API.
Use with caution. Use with caution.
''; '';
}; };
unifiUsername = mkOption { unifiUsername = mkOption {
type = types.str; type = types.str;
example = "ReadOnlyUser"; example = "ReadOnlyUser";
description = '' description = ''
username for authentication against UniFi Controller API. username for authentication against UniFi Controller API.
''; '';
}; };
unifiPassword = mkOption { unifiPassword = mkOption {
type = types.str; type = types.str;
description = '' description = ''
Password for authentication against UniFi Controller API. Password for authentication against UniFi Controller API.
''; '';
}; };
unifiTimeout = mkOption { unifiTimeout = mkOption {
type = types.str; type = types.str;
default = "5s"; default = "5s";
example = "2m"; example = "2m";
description = '' description = ''
Timeout including unit for UniFi Controller API requests. Timeout including unit for UniFi Controller API requests.
''; '';
};
}; };
}; serviceOpts = {
serviceOpts = { serviceConfig = {
serviceConfig = { DynamicUser = true;
DynamicUser = true; ExecStart = ''
ExecStart = '' ${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \
${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \ -telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \
-telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \ -unifi.addr ${cfg.unifiAddress} \
-unifi.addr ${cfg.unifiAddress} \ -unifi.username ${cfg.unifiUsername} \
-unifi.username ${cfg.unifiUsername} \ -unifi.password ${cfg.unifiPassword} \
-unifi.password ${cfg.unifiPassword} \ -unifi.timeout ${cfg.unifiTimeout} \
-unifi.timeout ${cfg.unifiTimeout} \ ${optionalString cfg.unifiInsecure "-unifi.insecure" } \
${optionalString cfg.unifiInsecure "-unifi.insecure" } \ ${concatStringsSep " \\\n " cfg.extraFlags}
${concatStringsSep " \\\n " cfg.extraFlags} '';
''; };
}; };
}; }
}

View File

@ -2,87 +2,88 @@
with lib; with lib;
let baseCfg:
cfg = config.services.prometheus.exporters.varnish; let
in cfg = baseCfg.varnish;
{ in
port = 9131; {
extraOpts = { port = 9131;
noExit = mkOption { extraOpts = {
type = types.bool; noExit = mkOption {
default = false; type = types.bool;
description = '' default = false;
Do not exit server on Varnish scrape errors. description = ''
''; Do not exit server on Varnish scrape errors.
'';
};
withGoMetrics = mkOption {
type = types.bool;
default = false;
description = ''
Export go runtime and http handler metrics.
'';
};
verbose = mkOption {
type = types.bool;
default = false;
description = ''
Enable verbose logging.
'';
};
raw = mkOption {
type = types.bool;
default = false;
description = ''
Enable raw stdout logging without timestamps.
'';
};
varnishStatPath = mkOption {
type = types.str;
default = "varnishstat";
description = ''
Path to varnishstat.
'';
};
instance = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
varnishstat -n value.
'';
};
healthPath = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Path under which to expose healthcheck. Disabled unless configured.
'';
};
telemetryPath = mkOption {
type = types.str;
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
}; };
withGoMetrics = mkOption { serviceOpts = {
type = types.bool; path = [ pkgs.varnish ];
default = false; serviceConfig = {
description = '' DynamicUser = true;
Export go runtime and http handler metrics. RestartSec = mkDefault 1;
''; ExecStart = ''
${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--varnishstat-path ${cfg.varnishStatPath} \
${concatStringsSep " \\\n " (cfg.extraFlags
++ optional (cfg.healthPath != null) "--web.health-path ${cfg.healthPath}"
++ optional (cfg.instance != null) "-n ${cfg.instance}"
++ optional cfg.noExit "--no-exit"
++ optional cfg.withGoMetrics "--with-go-metrics"
++ optional cfg.verbose "--verbose"
++ optional cfg.raw "--raw")}
'';
};
}; };
verbose = mkOption { }
type = types.bool;
default = false;
description = ''
Enable verbose logging.
'';
};
raw = mkOption {
type = types.bool;
default = false;
description = ''
Enable raw stdout logging without timestamps.
'';
};
varnishStatPath = mkOption {
type = types.str;
default = "varnishstat";
description = ''
Path to varnishstat.
'';
};
instance = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
varnishstat -n value.
'';
};
healthPath = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Path under which to expose healthcheck. Disabled unless configured.
'';
};
telemetryPath = mkOption {
type = types.str;
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
};
serviceOpts = {
path = [ pkgs.varnish ];
serviceConfig = {
DynamicUser = true;
RestartSec = mkDefault 1;
ExecStart = ''
${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--varnishstat-path ${cfg.varnishStatPath} \
${concatStringsSep " \\\n " (cfg.extraFlags
++ optional (cfg.healthPath != null) "--web.health-path ${cfg.healthPath}"
++ optional (cfg.instance != null) "-n ${cfg.instance}"
++ optional cfg.noExit "--no-exit"
++ optional cfg.withGoMetrics "--with-go-metrics"
++ optional cfg.verbose "--verbose"
++ optional cfg.raw "--raw")}
'';
};
};
}