1 { config, pkgs, lib, ... }:
6 cfg = config.services.prometheus.pushgateway;
9 opt "web.listen-address" cfg.web.listen-address
10 ++ opt "web.telemetry-path" cfg.web.telemetry-path
11 ++ opt "web.external-url" cfg.web.external-url
12 ++ opt "web.route-prefix" cfg.web.route-prefix
13 ++ optional cfg.persistMetrics ''--persistence.file="/var/lib/${cfg.stateDir}/metrics"''
14 ++ opt "persistence.interval" cfg.persistence.interval
15 ++ opt "log.level" cfg.log.level
16 ++ opt "log.format" cfg.log.format
19 opt = k : v : optional (v != null) ''--${k}="${v}"'';
23 services.prometheus.pushgateway = {
24 enable = mkEnableOption "Prometheus Pushgateway";
26 package = mkPackageOption pkgs "prometheus-pushgateway" { };
28 web.listen-address = mkOption {
29 type = types.nullOr types.str;
32 Address to listen on for the web interface, API and telemetry.
34 `null` will default to `:9091`.
38 web.telemetry-path = mkOption {
39 type = types.nullOr types.str;
42 Path under which to expose metrics.
44 `null` will default to `/metrics`.
48 web.external-url = mkOption {
49 type = types.nullOr types.str;
52 The URL under which Pushgateway is externally reachable.
56 web.route-prefix = mkOption {
57 type = types.nullOr types.str;
60 Prefix for the internal routes of web endpoints.
62 Defaults to the path of
63 {option}`services.prometheus.pushgateway.web.external-url`.
67 persistence.interval = mkOption {
68 type = types.nullOr types.str;
72 The minimum interval at which to write out the persistence file.
74 `null` will default to `5m`.
78 log.level = mkOption {
79 type = types.nullOr (types.enum ["debug" "info" "warn" "error" "fatal"]);
82 Only log messages with the given severity or above.
84 `null` will default to `info`.
88 log.format = mkOption {
89 type = types.nullOr types.str;
91 example = "logger:syslog?appname=bob&local=7";
93 Set the log target and format.
95 `null` will default to `logger:stderr`.
99 extraFlags = mkOption {
100 type = types.listOf types.str;
103 Extra commandline options when launching the Pushgateway.
107 persistMetrics = mkOption {
111 Whether to persist metrics to a file.
113 When enabled metrics will be saved to a file called
114 `metrics` in the directory
115 `/var/lib/pushgateway`. The directory below
116 `/var/lib` can be set using
117 {option}`services.prometheus.pushgateway.stateDir`.
121 stateDir = mkOption {
123 default = "pushgateway";
125 Directory below `/var/lib` to store metrics.
127 This directory will be created automatically using systemd's
128 StateDirectory mechanism when
129 {option}`services.prometheus.pushgateway.persistMetrics`
136 config = mkIf cfg.enable {
139 assertion = !hasPrefix "/" cfg.stateDir;
141 "The option services.prometheus.pushgateway.stateDir" +
142 " shouldn't be an absolute directory." +
143 " It should be a directory relative to /var/lib.";
146 systemd.services.pushgateway = {
147 wantedBy = [ "multi-user.target" ];
148 after = [ "network.target" ];
150 ExecStart = "${cfg.package}/bin/pushgateway" +
151 optionalString (length cmdlineArgs != 0) (" \\\n " +
152 concatStringsSep " \\\n " cmdlineArgs);
154 CapabilityBoundingSet = [ "" ];
155 DeviceAllow = [ "" ];
157 NoNewPrivileges = true;
159 MemoryDenyWriteExecute = true;
161 LockPersonality = true;
163 ProtectProc = "invisible";
164 ProtectSystem = "strict";
165 ProtectHome = "tmpfs";
168 PrivateDevices = true;
173 ProtectHostname = true;
175 ProtectKernelTunables = true;
176 ProtectKernelModules = true;
177 ProtectKernelLogs = true;
178 ProtectControlGroups = true;
182 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
183 RestrictNamespaces = true;
184 RestrictRealtime = true;
185 RestrictSUIDSGID = true;
187 StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;