Rollback versionning of services.prometheus.{exporters, alertmanager}.
This commit is contained in:
parent
e17b464a43
commit
bfbae97cfa
@ -4,33 +4,31 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.prometheus.alertmanager;
|
cfg = config.services.prometheus.alertmanager;
|
||||||
cfg2 = config.services.prometheus2.alertmanager;
|
mkConfigFile = pkgs.writeText "alertmanager.yml" (builtins.toJSON cfg.configuration);
|
||||||
mkConfigFile = amCfg:
|
|
||||||
pkgs.writeText "alertmanager.yml" (builtins.toJSON amCfg.configuration);
|
|
||||||
|
|
||||||
mkAlertmanagerYml = amCfg: let
|
checkedConfig = file: pkgs.runCommand "checked-config" { buildInputs = [ cfg.package ]; } ''
|
||||||
checkedConfig = file:
|
|
||||||
pkgs.runCommand "checked-config" { buildInputs = [ amCfg.package ]; } ''
|
|
||||||
ln -s ${file} $out
|
ln -s ${file} $out
|
||||||
amtool check-config $out
|
amtool check-config $out
|
||||||
'';
|
'';
|
||||||
yml = if amCfg.configText != null then
|
|
||||||
pkgs.writeText "alertmanager.yml" amCfg.configText
|
|
||||||
else mkConfigFile amCfg;
|
|
||||||
in
|
|
||||||
checkedConfig yml;
|
|
||||||
|
|
||||||
mkCmdlineArgs = amCfg:
|
alertmanagerYml = let
|
||||||
amCfg.extraFlags ++ [
|
yml = if cfg.configText != null then
|
||||||
"--config.file ${mkAlertmanagerYml amCfg}"
|
pkgs.writeText "alertmanager.yml" cfg.configText
|
||||||
"--web.listen-address ${amCfg.listenAddress}:${toString amCfg.port}"
|
else mkConfigFile;
|
||||||
"--log.level ${amCfg.logLevel}"
|
in checkedConfig yml;
|
||||||
] ++ (optional (amCfg.webExternalUrl != null)
|
|
||||||
"--web.external-url ${amCfg.webExternalUrl}"
|
cmdlineArgs = cfg.extraFlags ++ [
|
||||||
) ++ (optional (amCfg.logFormat != null)
|
"--config.file ${alertmanagerYml}"
|
||||||
"--log.format ${amCfg.logFormat}"
|
"--web.listen-address ${cfg.listenAddress}:${toString cfg.port}"
|
||||||
|
"--log.level ${cfg.logLevel}"
|
||||||
|
] ++ (optional (cfg.webExternalUrl != null)
|
||||||
|
"--web.external-url ${cfg.webExternalUrl}"
|
||||||
|
) ++ (optional (cfg.logFormat != null)
|
||||||
|
"--log.format ${cfg.logFormat}"
|
||||||
);
|
);
|
||||||
amOptions = {
|
in {
|
||||||
|
options = {
|
||||||
|
services.prometheus.alertmanager = {
|
||||||
enable = mkEnableOption "Prometheus Alertmanager";
|
enable = mkEnableOption "Prometheus Alertmanager";
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
@ -137,27 +135,30 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
mkAMConfig = amCfg: amVersion: [
|
};
|
||||||
(mkIf amCfg.enable {
|
|
||||||
|
config = mkMerge [
|
||||||
|
(mkIf cfg.enable {
|
||||||
assertions = singleton {
|
assertions = singleton {
|
||||||
assertion = amCfg.configuration != null || amCfg.configText != null;
|
assertion = cfg.configuration != null || cfg.configText != null;
|
||||||
message = "Can not enable alertmanager without a configuration. "
|
message = "Can not enable alertmanager without a configuration. "
|
||||||
+ "Set either the `configuration` or `configText` attribute.";
|
+ "Set either the `configuration` or `configText` attribute.";
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
(mkIf amCfg.enable {
|
(mkIf cfg.enable {
|
||||||
networking.firewall.allowedTCPPorts = optional amCfg.openFirewall amCfg.port;
|
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
|
||||||
|
|
||||||
systemd.services."alertmanager${amVersion}" = {
|
systemd.services.alertmanager = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
script = ''
|
script = ''
|
||||||
${amCfg.package}/bin/alertmanager \
|
${cfg.package}/bin/alertmanager \
|
||||||
${concatStringsSep " \\\n " (mkCmdlineArgs amCfg)}
|
${concatStringsSep " \\\n " cmdlineArgs}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = amCfg.user;
|
User = cfg.user;
|
||||||
Group = amCfg.group;
|
Group = cfg.group;
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
PrivateTmp = true;
|
PrivateTmp = true;
|
||||||
WorkingDirectory = "/tmp";
|
WorkingDirectory = "/tmp";
|
||||||
@ -166,11 +167,4 @@ let
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
in {
|
|
||||||
options = {
|
|
||||||
services.prometheus.alertmanager = amOptions;
|
|
||||||
services.prometheus2.alertmanager = amOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkMerge ((mkAMConfig cfg "") ++ (mkAMConfig cfg2 "2"));
|
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ let
|
|||||||
cfg2 = config.services.prometheus2;
|
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;
|
||||||
@ -693,11 +691,11 @@ in {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
(mkIf cfg2.enable {
|
(mkIf cfg2.enable {
|
||||||
users.groups.${prom2Group}.gid = config.ids.gids.prometheus2;
|
users.groups.${promGroup}.gid = config.ids.gids.prometheus2;
|
||||||
users.users.${prom2User} = {
|
users.users.${promUser} = {
|
||||||
description = "Prometheus2 daemon user";
|
description = "Prometheus2 daemon user";
|
||||||
uid = config.ids.uids.prometheus2;
|
uid = config.ids.uids.prometheus2;
|
||||||
group = prom2Group;
|
group = promGroup;
|
||||||
home = cfg2.dataDir;
|
home = cfg2.dataDir;
|
||||||
createHome = true;
|
createHome = true;
|
||||||
};
|
};
|
||||||
@ -710,7 +708,7 @@ in {
|
|||||||
${concatStringsSep " \\\n " cmdlineArgs2}
|
${concatStringsSep " \\\n " cmdlineArgs2}
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = prom2User;
|
User = promUser;
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
WorkingDirectory = cfg2.dataDir;
|
WorkingDirectory = cfg2.dataDir;
|
||||||
};
|
};
|
||||||
|
@ -4,10 +4,8 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.prometheus.exporters;
|
cfg = config.services.prometheus.exporters;
|
||||||
cfg2 = config.services.prometheus2.exporters;
|
|
||||||
|
|
||||||
# each attribute in `exporterOpts` is a function that when executed
|
# each attribute in `exporterOpts` is expected to have specified:
|
||||||
# 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
|
||||||
@ -110,16 +108,11 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
mkSubModules = exCfg:
|
mkSubModules = (foldl' (a: b: a//b) {}
|
||||||
(foldl' (a: b: a//b) {}
|
(mapAttrsToList (name: opts: mkSubModule {
|
||||||
(mapAttrsToList (name: confGen:
|
|
||||||
let
|
|
||||||
conf = (confGen exCfg);
|
|
||||||
in
|
|
||||||
mkSubModule {
|
|
||||||
inherit name;
|
inherit name;
|
||||||
inherit (conf) port serviceOpts;
|
inherit (opts) port serviceOpts;
|
||||||
extraOpts = conf.extraOpts or {};
|
extraOpts = opts.extraOpts or {};
|
||||||
}) exporterOpts)
|
}) exporterOpts)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -140,36 +133,11 @@ 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 cfg);
|
options = (mkSubModules);
|
||||||
};
|
};
|
||||||
description = "Prometheus exporter configuration";
|
description = "Prometheus exporter configuration";
|
||||||
default = {};
|
default = {};
|
||||||
@ -184,24 +152,25 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
options.services.prometheus2.exporters = mkOption {
|
config = mkMerge ([{
|
||||||
type = types.submodule {
|
assertions = [{
|
||||||
options = (mkSubModules cfg2);
|
assertion = (cfg.snmp.configurationPath == null) != (cfg.snmp.configuration == null);
|
||||||
};
|
message = ''
|
||||||
description = "Prometheus 2 exporter configuration";
|
Please ensure you have either `services.prometheus.exporters.snmp.configuration'
|
||||||
default = {};
|
or `services.prometheus.exporters.snmp.configurationPath' set!
|
||||||
example = literalExample ''
|
|
||||||
{
|
|
||||||
node = {
|
|
||||||
enable = true;
|
|
||||||
enabledCollectors = [ "systemd" ];
|
|
||||||
};
|
|
||||||
varnish.enable = true;
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
}];
|
||||||
|
}] ++ [(mkIf config.services.minio.enable {
|
||||||
config = mkMerge ((mkExportersConfig cfg "") ++ (mkExportersConfig cfg2 "2"));
|
services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
|
||||||
|
services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;
|
||||||
|
services.prometheus.exporters.minio.minioAccessSecret = mkDefault config.services.minio.secretKey;
|
||||||
|
})] ++ (mapAttrsToList (name: conf:
|
||||||
|
mkExporterConf {
|
||||||
|
inherit name;
|
||||||
|
inherit (conf) serviceOpts;
|
||||||
|
conf = cfg.${name};
|
||||||
|
}) exporterOpts)
|
||||||
|
);
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
doc = ./exporters.xml;
|
doc = ./exporters.xml;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.bind;
|
cfg = config.services.prometheus.exporters.bind;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9119;
|
port = 9119;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.blackbox;
|
cfg = config.services.prometheus.exporters.blackbox;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9115;
|
port = 9115;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.collectd;
|
cfg = config.services.prometheus.exporters.collectd;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9103;
|
port = 9103;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.dnsmasq;
|
cfg = config.services.prometheus.exporters.dnsmasq;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9153;
|
port = 9153;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.dovecot;
|
cfg = config.services.prometheus.exporters.dovecot;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9166;
|
port = 9166;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.fritzbox;
|
cfg = config.services.prometheus.exporters.fritzbox;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9133;
|
port = 9133;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.json;
|
cfg = config.services.prometheus.exporters.json;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 7979;
|
port = 7979;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.minio;
|
cfg = config.services.prometheus.exporters.minio;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9290;
|
port = 9290;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.nginx;
|
cfg = config.services.prometheus.exporters.nginx;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9113;
|
port = 9113;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.node;
|
cfg = config.services.prometheus.exporters.node;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9100;
|
port = 9100;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.postfix;
|
cfg = config.services.prometheus.exporters.postfix;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9154;
|
port = 9154;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.snmp;
|
cfg = config.services.prometheus.exporters.snmp;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9116;
|
port = 9116;
|
||||||
@ -61,10 +60,10 @@ baseCfg:
|
|||||||
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}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.surfboard;
|
cfg = config.services.prometheus.exporters.surfboard;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9239;
|
port = 9239;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.tor;
|
cfg = config.services.prometheus.exporters.tor;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9130;
|
port = 9130;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.unifi;
|
cfg = config.services.prometheus.exporters.unifi;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9130;
|
port = 9130;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
baseCfg:
|
|
||||||
let
|
let
|
||||||
cfg = baseCfg.varnish;
|
cfg = config.services.prometheus.exporters.varnish;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
port = 9131;
|
port = 9131;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user