2019-04-15 23:46:25 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.prometheus.pushgateway;
|
|
|
|
|
|
|
|
cmdlineArgs =
|
|
|
|
opt "web.listen-address" cfg.web.listen-address
|
|
|
|
++ opt "web.telemetry-path" cfg.web.telemetry-path
|
|
|
|
++ opt "web.external-url" cfg.web.external-url
|
|
|
|
++ opt "web.route-prefix" cfg.web.route-prefix
|
2024-08-30 00:47:01 +02:00
|
|
|
++ lib.optional cfg.persistMetrics ''--persistence.file="/var/lib/${cfg.stateDir}/metrics"''
|
2019-04-15 23:46:25 +02:00
|
|
|
++ opt "persistence.interval" cfg.persistence.interval
|
|
|
|
++ opt "log.level" cfg.log.level
|
|
|
|
++ opt "log.format" cfg.log.format
|
|
|
|
++ cfg.extraFlags;
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
opt = k: v: lib.optional (v != null) ''--${k}="${v}"'';
|
2019-04-15 23:46:25 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.prometheus.pushgateway = {
|
2024-08-30 00:47:01 +02:00
|
|
|
enable = lib.mkEnableOption "Prometheus Pushgateway";
|
2019-04-15 23:46:25 +02:00
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
package = lib.mkPackageOption pkgs "prometheus-pushgateway" { };
|
2019-04-15 23:46:25 +02:00
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
web.listen-address = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Address to listen on for the web interface, API and telemetry.
|
|
|
|
|
|
|
|
`null` will default to `:9091`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
web.telemetry-path = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path under which to expose metrics.
|
|
|
|
|
|
|
|
`null` will default to `/metrics`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
web.external-url = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The URL under which Pushgateway is externally reachable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
web.route-prefix = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Prefix for the internal routes of web endpoints.
|
|
|
|
|
|
|
|
Defaults to the path of
|
|
|
|
{option}`services.prometheus.pushgateway.web.external-url`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
persistence.interval = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
example = "10m";
|
|
|
|
description = ''
|
|
|
|
The minimum interval at which to write out the persistence file.
|
|
|
|
|
|
|
|
`null` will default to `5m`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
log.level = lib.mkOption {
|
|
|
|
type = lib.types.nullOr (
|
|
|
|
lib.types.enum [
|
|
|
|
"debug"
|
|
|
|
"info"
|
|
|
|
"warn"
|
|
|
|
"error"
|
|
|
|
"fatal"
|
2024-12-10 20:26:33 +01:00
|
|
|
]
|
2024-08-30 00:47:01 +02:00
|
|
|
);
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Only log messages with the given severity or above.
|
|
|
|
|
|
|
|
`null` will default to `info`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
log.format = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = null;
|
|
|
|
example = "logger:syslog?appname=bob&local=7";
|
|
|
|
description = ''
|
|
|
|
Set the log target and format.
|
|
|
|
|
|
|
|
`null` will default to `logger:stderr`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
extraFlags = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra commandline options when launching the Pushgateway.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
persistMetrics = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to persist metrics to a file.
|
|
|
|
|
|
|
|
When enabled metrics will be saved to a file called
|
|
|
|
`metrics` in the directory
|
|
|
|
`/var/lib/pushgateway`. The directory below
|
|
|
|
`/var/lib` can be set using
|
|
|
|
{option}`services.prometheus.pushgateway.stateDir`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
stateDir = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2019-04-15 23:46:25 +02:00
|
|
|
default = "pushgateway";
|
|
|
|
description = ''
|
|
|
|
Directory below `/var/lib` to store metrics.
|
|
|
|
|
|
|
|
This directory will be created automatically using systemd's
|
|
|
|
StateDirectory mechanism when
|
|
|
|
{option}`services.prometheus.pushgateway.persistMetrics`
|
|
|
|
is enabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:47:01 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2019-04-15 23:46:25 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
2024-08-30 00:47:01 +02:00
|
|
|
assertion = !lib.hasPrefix "/" cfg.stateDir;
|
2019-04-15 23:46:25 +02:00
|
|
|
message =
|
|
|
|
"The option services.prometheus.pushgateway.stateDir"
|
|
|
|
+ " shouldn't be an absolute directory."
|
|
|
|
+ " It should be a directory relative to /var/lib.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
systemd.services.pushgateway = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart =
|
|
|
|
"${cfg.package}/bin/pushgateway"
|
2024-08-30 00:47:01 +02:00
|
|
|
+ lib.optionalString (lib.length cmdlineArgs != 0) (
|
|
|
|
" \\\n " + lib.concatStringsSep " \\\n " cmdlineArgs
|
|
|
|
);
|
2024-06-24 00:13:04 +01:00
|
|
|
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
|
|
|
DeviceAllow = [ "" ];
|
|
|
|
DynamicUser = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = "tmpfs";
|
|
|
|
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateIPC = true;
|
|
|
|
|
|
|
|
ProcSubset = "pid";
|
|
|
|
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
|
|
|
|
Restart = "always";
|
|
|
|
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
2019-04-15 23:46:25 +02:00
|
|
|
StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;
|
2024-06-24 00:13:04 +01:00
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@cpu-emulation"
|
|
|
|
"~@privileged"
|
|
|
|
"~@reboot"
|
|
|
|
"~@setuid"
|
|
|
|
"~@swap"
|
|
|
|
];
|
2019-04-15 23:46:25 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|