@@ -0,0 +1,47 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.prometheus.nodeExporter;
7+ cmdlineArgs = cfg.extraFlags ++ [
8+ "-web.listen-address=${cfg.listenAddress}"
9+ ];
10+in {
11+ options = {
12+ services.prometheus.nodeExporter = {
13+ enable = mkEnableOption "Enable the Prometheus node exporter (CPU stats etc).";
14+ listenAddress = mkOption {
15+ type = types.str;
16+ default = "0.0.0.0:9100";
17+ description = ''
18+ Address to listen on.
19+ '';
20+ };
21+ extraFlags = mkOption {
22+ type = types.listOf types.str;
23+ default = [];
24+ description = ''
25+ Extra commandline options when launching the node exporter.
26+ '';
27+ };
28+ };
29+ };
30+
31+ config = mkIf cfg.enable {
32+ systemd.services.prometheus-node-exporter = {
33+ description = "Prometheus exporter for machine metrics";
34+ unitConfig.Documentation = "https://github.com/prometheus/node_exporter";
35+ wantedBy = [ "multi-user.target" ];
36+ script = ''
37+ exec ${pkgs.prometheus-node-exporter}/bin/node_exporter \
38+ ${concatStringsSep " \\\n " cmdlineArgs}
39+ '';
40+ serviceConfig = {
41+ User = "nobody";
42+ Restart = "always";
43+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
44+ };
45+ };
46+ };
47+}