1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.varnish; 7in 8{ 9 port = 9131; 10 extraOpts = { 11 noExit = mkOption { 12 type = types.bool; 13 default = false; 14 description = '' 15 Do not exit server on Varnish scrape errors. 16 ''; 17 }; 18 withGoMetrics = mkOption { 19 type = types.bool; 20 default = false; 21 description = '' 22 Export go runtime and http handler metrics. 23 ''; 24 }; 25 verbose = mkOption { 26 type = types.bool; 27 default = false; 28 description = '' 29 Enable verbose logging. 30 ''; 31 }; 32 raw = mkOption { 33 type = types.bool; 34 default = false; 35 description = '' 36 Enable raw stdout logging without timestamps. 37 ''; 38 }; 39 varnishStatPath = mkOption { 40 type = types.str; 41 default = "varnishstat"; 42 description = '' 43 Path to varnishstat. 44 ''; 45 }; 46 instance = mkOption { 47 type = types.nullOr types.str; 48 default = null; 49 description = '' 50 varnishstat -n value. 51 ''; 52 }; 53 healthPath = mkOption { 54 type = types.nullOr types.str; 55 default = null; 56 description = '' 57 Path under which to expose healthcheck. Disabled unless configured. 58 ''; 59 }; 60 telemetryPath = mkOption { 61 type = types.str; 62 default = "/metrics"; 63 description = '' 64 Path under which to expose metrics. 65 ''; 66 }; 67 }; 68 serviceOpts = { 69 path = [ pkgs.varnish ]; 70 serviceConfig = { 71 RestartSec = mkDefault 1; 72 DynamicUser = false; 73 ExecStart = '' 74 ${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \ 75 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 76 --web.telemetry-path ${cfg.telemetryPath} \ 77 --varnishstat-path ${escapeShellArg cfg.varnishStatPath} \ 78 ${concatStringsSep " \\\n " (cfg.extraFlags 79 ++ optional (cfg.healthPath != null) "--web.health-path ${cfg.healthPath}" 80 ++ optional (cfg.instance != null) "-n ${escapeShellArg cfg.instance}" 81 ++ optional cfg.noExit "--no-exit" 82 ++ optional cfg.withGoMetrics "--with-go-metrics" 83 ++ optional cfg.verbose "--verbose" 84 ++ optional cfg.raw "--raw")} 85 ''; 86 }; 87 }; 88}