Merge branch 'prometheus-node-exporter' of https://github.com/teh/nixpkgs into prometheus-nixos-exporter

This commit is contained in:
Robin Gloster 2016-09-15 20:37:04 +02:00
commit 55b8430f6f
No known key found for this signature in database
GPG Key ID: 5E4C836C632C2882

View File

@ -4,6 +4,9 @@ with lib;
let let
cfg = config.services.prometheus.nodeExporter; cfg = config.services.prometheus.nodeExporter;
cmdlineArgs = cfg.extraFlags ++ [
"-web.listen-address=${cfg.listenAddress}"
];
in { in {
options = { options = {
services.prometheus.nodeExporter = { services.prometheus.nodeExporter = {
@ -33,6 +36,14 @@ in {
Collectors to enable, additionally to the defaults. Collectors to enable, additionally to the defaults.
''; '';
}; };
extraFlags = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Extra commandline options when launching the node exporter.
'';
};
}; };
}; };
@ -40,19 +51,23 @@ in {
networking.firewall.allowedTCPPorts = [ cfg.port ]; networking.firewall.allowedTCPPorts = [ cfg.port ];
systemd.services.prometheus-node-exporter = { systemd.services.prometheus-node-exporter = {
description = "Prometheus exporter for machine metrics";
unitConfig.Documentation = "https://github.com/prometheus/node_exporter";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network.target" ]; after = [ "network.target" ];
script = '' script = ''
${pkgs.prometheus-node-exporter.bin}/bin/node_exporter \ exec ${pkgs.prometheus-node-exporter}/bin/node_exporter \
${optionalString (cfg.enabledCollectors != []) ${optionalString (cfg.enabledCollectors != [])
''-collectors.enabled ${concatStringsSep "," cfg.enabledCollectors}''} \ ''-collectors.enabled ${concatStringsSep "," cfg.enabledCollectors}''} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${concatStringsSep " \\\n " cfg.extraFlags}
''; '';
serviceConfig = { serviceConfig = {
User = "nobody"; User = "nobody";
Restart = "always"; Restart = "always";
PrivateTmp = true; PrivateTmp = true;
WorkingDirectory = /tmp; WorkingDirectory = /tmp;
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
}; };
}; };
}; };