52 lines
1.4 KiB
Nix
52 lines
1.4 KiB
Nix
![]() |
{ 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";
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
}
|