2024-03-21 05:26:03 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
options,
|
|
|
|
...
|
|
|
|
}:
|
2018-03-09 21:33:09 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.prometheus.exporters.node;
|
2024-04-24 14:41:17 -04:00
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
concatStringsSep
|
|
|
|
concatMapStringsSep
|
|
|
|
any
|
|
|
|
optionals
|
|
|
|
;
|
2022-10-30 14:59:05 +04:00
|
|
|
collectorIsEnabled = final: any (collector: (final == collector)) cfg.enabledCollectors;
|
|
|
|
collectorIsDisabled = final: any (collector: (final == collector)) cfg.disabledCollectors;
|
2018-03-09 21:33:09 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
port = 9100;
|
|
|
|
extraOpts = {
|
|
|
|
enabledCollectors = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.listOf types.str;
|
2018-03-09 21:33:09 +01:00
|
|
|
default = [ ];
|
2021-10-03 18:06:03 +02:00
|
|
|
example = [ "systemd" ];
|
2018-03-09 21:33:09 +01:00
|
|
|
description = ''
|
|
|
|
Collectors to enable. The collectors listed here are enabled in addition to the default ones.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
disabledCollectors = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2021-10-03 18:06:03 +02:00
|
|
|
example = [ "timex" ];
|
2018-03-09 21:33:09 +01:00
|
|
|
description = ''
|
|
|
|
Collectors to disable which are enabled by default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
serviceOpts = {
|
|
|
|
serviceConfig = {
|
2019-08-02 15:23:23 +02:00
|
|
|
DynamicUser = false;
|
2018-03-20 19:42:00 +01:00
|
|
|
RuntimeDirectory = "prometheus-node-exporter";
|
2018-03-09 21:33:09 +01:00
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.prometheus-node-exporter}/bin/node_exporter \
|
|
|
|
${concatMapStringsSep " " (x: "--collector." + x) cfg.enabledCollectors} \
|
|
|
|
${concatMapStringsSep " " (x: "--no-collector." + x) cfg.disabledCollectors} \
|
2019-06-20 21:04:36 +00:00
|
|
|
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} ${concatStringsSep " " cfg.extraFlags}
|
2018-03-09 21:33:09 +01:00
|
|
|
'';
|
2022-10-30 14:59:05 +04:00
|
|
|
RestrictAddressFamilies =
|
|
|
|
optionals (collectorIsEnabled "logind" || collectorIsEnabled "systemd") [
|
2021-10-18 19:18:55 +02:00
|
|
|
# needs access to dbus via unix sockets (logind/systemd)
|
|
|
|
"AF_UNIX"
|
2022-10-30 14:59:05 +04:00
|
|
|
]
|
|
|
|
++ optionals
|
|
|
|
(collectorIsEnabled "network_route" || collectorIsEnabled "wifi" || !collectorIsDisabled "netdev")
|
|
|
|
[
|
2021-10-18 19:18:55 +02:00
|
|
|
# needs netlink sockets for wireless collector
|
|
|
|
"AF_NETLINK"
|
|
|
|
];
|
2021-10-13 15:37:02 +02:00
|
|
|
# The timex collector needs to access clock APIs
|
2022-10-30 14:59:05 +04:00
|
|
|
ProtectClock = collectorIsDisabled "timex";
|
2022-01-04 08:14:36 +01:00
|
|
|
# Allow space monitoring under /home
|
|
|
|
ProtectHome = true;
|
2018-03-09 21:33:09 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|