@@ -0,0 +1,59 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.prometheus.nodeExporter;
7+in {
8+ options = {
9+ services.prometheus.nodeExporter = {
10+ enable = mkEnableOption "prometheus node exporter";
11+
12+ port = mkOption {
13+ type = types.int;
14+ default = 9100;
15+ description = ''
16+ Port to listen on.
17+ '';
18+ };
19+
20+ listenAddress = mkOption {
21+ type = types.string;
22+ default = "0.0.0.0";
23+ description = ''
24+ Address to listen on.
25+ '';
26+ };
27+
28+ enabledCollectors = mkOption {
29+ type = types.listOf types.string;
30+ default = [];
31+ example = ''[ "systemd" ]'';
32+ description = ''
33+ Collectors to enable, additionally to the defaults.
34+ '';
35+ };
36+ };
37+ };
38+
39+ config = mkIf cfg.enable {
40+ networking.firewall.allowedTCPPorts = [ cfg.port ];
41+
42+ systemd.services.prometheus-node-exporter = {
43+ wantedBy = [ "multi-user.target" ];
44+ after = [ "network.target" ];
45+ script = ''
46+ ${pkgs.prometheus-node-exporter.bin}/bin/node_exporter \
47+ ${optionalString (cfg.enabledCollectors != [])
48+ ''-collectors.enabled ${concatStringsSep "," cfg.enabledCollectors}''} \
49+ -web.listen-address ${cfg.listenAddress}:${toString cfg.port}
50+ '';
51+ serviceConfig = {
52+ User = "nobody";
53+ Restart = "always";
54+ PrivateTmp = true;
55+ WorkingDirectory = /tmp;
56+ };
57+ };
58+ };
59+}