prometheus module: add nginxExporter

This commit is contained in:
Robin Gloster 2016-07-26 14:43:45 +00:00
parent f1b8c3b119
commit 39e8eaf8b6
2 changed files with 59 additions and 0 deletions

View File

@ -308,6 +308,7 @@
./services/monitoring/munin.nix
./services/monitoring/nagios.nix
./services/monitoring/prometheus/default.nix
./services/monitoring/prometheus/nginx-exporter.nix
./services/monitoring/prometheus/node-exporter.nix
./services/monitoring/prometheus/alertmanager.nix
./services/monitoring/riemann.nix

View File

@ -0,0 +1,58 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.prometheus.nginxExporter;
in {
options = {
services.prometheus.nginxExporter = {
enable = mkEnableOption "prometheus nginx exporter";
port = mkOption {
type = types.int;
default = 9113;
description = ''
Port to listen on.
'';
};
listenAddress = mkOption {
type = types.string;
default = "0.0.0.0";
description = ''
Address to listen on.
'';
};
scrapeUri = mkOption {
type = types.string;
default = "http://localhost/nginx_status";
description = ''
Address to access the nginx status page.
Can be enabled with services.nginx.statusPage = true.
'';
};
};
};
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ cfg.port ];
systemd.services.prometheus-nginx-exporter = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "nginx.service" ];
script = ''
${pkgs.prometheus-nginx-exporter.bin}/bin/nginx_exporter \
-telemetry.address ${cfg.listenAddress}:${toString cfg.port} \
-nginx.scrape_uri ${cfg.scrapeUri}
'';
serviceConfig = {
User = "nobody";
Restart = "always";
PrivateTmp = true;
WorkingDirectory = /tmp;
};
};
};
}