promeutheus.nginxExporter: add improvements

- use ExecStart and ExecReload
 - add extraFlags
This commit is contained in:
Corbin 2016-11-26 19:56:25 -08:00 committed by Robin Gloster
parent 39e8eaf8b6
commit 363fa27448

View File

@ -33,6 +33,14 @@ in {
Can be enabled with services.nginx.statusPage = true. Can be enabled with services.nginx.statusPage = true.
''; '';
}; };
extraFlags = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Extra commandline options when launching the nginx exporter.
'';
};
}; };
}; };
@ -40,18 +48,22 @@ in {
networking.firewall.allowedTCPPorts = [ cfg.port ]; networking.firewall.allowedTCPPorts = [ cfg.port ];
systemd.services.prometheus-nginx-exporter = { systemd.services.prometheus-nginx-exporter = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "nginx.service" ]; after = [ "network.target" "nginx.service" ];
script = '' description = "Prometheus exporter for nginx metrics";
${pkgs.prometheus-nginx-exporter.bin}/bin/nginx_exporter \ unitConfig.Documentation = "https://github.com/discordianfish/nginx_exporter";
-telemetry.address ${cfg.listenAddress}:${toString cfg.port} \ wantedBy = [ "multi-user.target" ];
-nginx.scrape_uri ${cfg.scrapeUri}
'';
serviceConfig = { serviceConfig = {
User = "nobody"; User = "nobody";
Restart = "always"; Restart = "always";
PrivateTmp = true; PrivateTmp = true;
WorkingDirectory = /tmp; WorkingDirectory = /tmp;
ExecStart = ''
${pkgs.prometheus-nginx-exporter}/bin/nginx_exporter \
-nginx.scrape_uri '${cfg.scrapeUri}' \
-telemetry.address ${cfg.listenAddress}:${toString cfg.port} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
}; };
}; };
}; };