2019-07-17 12:19:18 +00:00
|
|
|
{ config, lib, pkgs, options }:
|
2018-03-09 20:33:09 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.prometheus.exporters.node;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
port = 9100;
|
|
|
|
extraOpts = {
|
|
|
|
enabledCollectors = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.listOf types.str;
|
2018-03-09 20:33:09 +00:00
|
|
|
default = [];
|
2021-10-03 16:06:03 +00:00
|
|
|
example = [ "systemd" ];
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-03-09 20:33:09 +00:00
|
|
|
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 16:06:03 +00:00
|
|
|
example = [ "timex" ];
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-03-09 20:33:09 +00:00
|
|
|
Collectors to disable which are enabled by default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
serviceOpts = {
|
|
|
|
serviceConfig = {
|
2019-08-02 13:23:23 +00:00
|
|
|
DynamicUser = false;
|
2018-03-20 18:42:00 +00:00
|
|
|
RuntimeDirectory = "prometheus-node-exporter";
|
2018-03-09 20:33:09 +00: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 20:33:09 +00:00
|
|
|
'';
|
2021-10-18 17:18:55 +00:00
|
|
|
RestrictAddressFamilies = optionals (any (collector: (collector == "logind" || collector == "systemd")) cfg.enabledCollectors) [
|
|
|
|
# needs access to dbus via unix sockets (logind/systemd)
|
|
|
|
"AF_UNIX"
|
|
|
|
] ++ optionals (any (collector: (collector == "network_route" || collector == "wifi")) cfg.enabledCollectors) [
|
|
|
|
# needs netlink sockets for wireless collector
|
|
|
|
"AF_NETLINK"
|
|
|
|
];
|
2021-10-13 13:37:02 +00:00
|
|
|
# The timex collector needs to access clock APIs
|
2021-10-18 17:18:55 +00:00
|
|
|
ProtectClock = any (collector: collector == "timex") cfg.disabledCollectors;
|
2022-01-04 07:14:36 +00:00
|
|
|
# Allow space monitoring under /home
|
|
|
|
ProtectHome = true;
|
2018-03-09 20:33:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|