···
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 = mkOption {
27
+
type = types.package;
28
+
default = pkgs.prometheus-pushgateway;
29
+
defaultText = "pkgs.prometheus-pushgateway";
31
+
Package that should be used for the prometheus pushgateway.
35
+
web.listen-address = mkOption {
36
+
type = types.nullOr types.str;
39
+
Address to listen on for the web interface, API and telemetry.
41
+
<literal>null</literal> will default to <literal>:9091</literal>.
45
+
web.telemetry-path = mkOption {
46
+
type = types.nullOr types.str;
49
+
Path under which to expose metrics.
51
+
<literal>null</literal> will default to <literal>/metrics</literal>.
55
+
web.external-url = mkOption {
56
+
type = types.nullOr types.str;
59
+
The URL under which Pushgateway is externally reachable.
63
+
web.route-prefix = mkOption {
64
+
type = types.nullOr types.str;
67
+
Prefix for the internal routes of web endpoints.
69
+
Defaults to the path of
70
+
<option>services.prometheus.pushgateway.web.external-url</option>.
74
+
persistence.interval = mkOption {
75
+
type = types.nullOr types.str;
79
+
The minimum interval at which to write out the persistence file.
81
+
<literal>null</literal> will default to <literal>5m</literal>.
85
+
log.level = mkOption {
86
+
type = types.nullOr (types.enum ["debug" "info" "warn" "error" "fatal"]);
89
+
Only log messages with the given severity or above.
91
+
<literal>null</literal> will default to <literal>info</literal>.
95
+
log.format = mkOption {
96
+
type = types.nullOr types.str;
98
+
example = "logger:syslog?appname=bob&local=7";
100
+
Set the log target and format.
102
+
<literal>null</literal> will default to <literal>logger:stderr</literal>.
106
+
extraFlags = mkOption {
107
+
type = types.listOf types.str;
110
+
Extra commandline options when launching the Pushgateway.
114
+
persistMetrics = mkOption {
118
+
Whether to persist metrics to a file.
120
+
When enabled metrics will be saved to a file called
121
+
<literal>metrics</literal> in the directory
122
+
<literal>/var/lib/pushgateway</literal>. The directory below
123
+
<literal>/var/lib</literal> can be set using
124
+
<option>services.prometheus.pushgateway.stateDir</option>.
128
+
stateDir = mkOption {
130
+
default = "pushgateway";
132
+
Directory below <literal>/var/lib</literal> to store metrics.
134
+
This directory will be created automatically using systemd's
135
+
StateDirectory mechanism when
136
+
<option>services.prometheus.pushgateway.persistMetrics</option>
143
+
config = mkIf cfg.enable {
146
+
assertion = !hasPrefix "/" cfg.stateDir;
148
+
"The option services.prometheus.pushgateway.stateDir" +
149
+
" shouldn't be an absolute directory." +
150
+
" It should be a directory relative to /var/lib.";
153
+
systemd.services.pushgateway = {
154
+
wantedBy = [ "multi-user.target" ];
155
+
after = [ "network.target" ];
157
+
Restart = "always";
158
+
DynamicUser = true;
159
+
ExecStart = "${cfg.package}/bin/pushgateway" +
160
+
optionalString (length cmdlineArgs != 0) (" \\\n " +
161
+
concatStringsSep " \\\n " cmdlineArgs);
162
+
StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;