about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring
diff options
context:
space:
mode:
authorCorbin <cds@corbinsimpson.com>2016-11-27 00:15:19 -0800
committerRobin Gloster <mail@glob.in>2017-01-09 15:20:26 +0100
commit1b839a586bef5d9dbb30b85388c2977b86df4fe5 (patch)
treea67a71824f6b846a289de36d7370eb80b3a84ad1 /nixos/modules/services/monitoring
parent51b247bff8012d123dd78c8fa7f2fc965a733c93 (diff)
downloadnixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar.gz
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar.bz2
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar.lz
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar.xz
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.tar.zst
nixlib-1b839a586bef5d9dbb30b85388c2977b86df4fe5.zip
prometheus module: add varnishExporter
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r--nixos/modules/services/monitoring/prometheus/varnish-exporter.nix51
1 files changed, 51 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/varnish-exporter.nix b/nixos/modules/services/monitoring/prometheus/varnish-exporter.nix
new file mode 100644
index 000000000000..0f608760e917
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/varnish-exporter.nix
@@ -0,0 +1,51 @@
+{ config, pkgs, lib, ... }:
+
+# Shamelessly cribbed from nginx-exporter.nix. ~ C.
+with lib;
+
+let
+  cfg = config.services.prometheus.varnishExporter;
+in {
+  options = {
+    services.prometheus.varnishExporter = {
+      enable = mkEnableOption "prometheus Varnish exporter";
+
+      port = mkOption {
+        type = types.int;
+        default = 9131;
+        description = ''
+          Port to listen on.
+        '';
+      };
+
+      extraFlags = mkOption {
+        type = types.listOf types.str;
+        default = [];
+        description = ''
+          Extra commandline options when launching the Varnish exporter.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.prometheus-varnish-exporter = {
+      description = "Prometheus exporter for Varnish metrics";
+      unitConfig.Documentation = "https://github.com/jonnenauha/prometheus_varnish_exporter";
+      wantedBy = [ "multi-user.target" ];
+      path = [ pkgs.varnish ];
+      script = ''
+        exec ${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \
+          -web.listen-address :${toString cfg.port} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+      serviceConfig = {
+        User = "nobody";
+        Restart = "always";
+        PrivateTmp = true;
+        WorkingDirectory = /tmp;
+        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
+      };
+    };
+  };
+}