summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorRobin Gloster <mail@glob.in>2016-07-26 14:43:45 +0000
committerRobin Gloster <mail@glob.in>2017-01-09 15:20:26 +0100
commit39e8eaf8b6f985fcae5931bda39679d657fea1ed (patch)
treea0b71b4c0349206981ed080c173e169b85c1a8c0 /nixos
parentf1b8c3b1190fdf213b8944e8963d1623b432b9ac (diff)
downloadnixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar.gz
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar.bz2
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar.lz
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar.xz
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.tar.zst
nixlib-39e8eaf8b6f985fcae5931bda39679d657fea1ed.zip
prometheus module: add nginxExporter
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/nginx-exporter.nix58
2 files changed, 59 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 2171809e51be..df482fbfcaf4 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -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
diff --git a/nixos/modules/services/monitoring/prometheus/nginx-exporter.nix b/nixos/modules/services/monitoring/prometheus/nginx-exporter.nix
new file mode 100644
index 000000000000..923b6db74107
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/nginx-exporter.nix
@@ -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;
+      };
+    };
+  };
+}