From 0ded9a63a30eb9d42ad76fd28d7de836c2f82bdc Mon Sep 17 00:00:00 2001 From: Tom Hunger Date: Sun, 11 Sep 2016 22:45:17 +0100 Subject: [PATCH] prometheus-node-exporter: Add module. --- nixos/modules/module-list.nix | 1 + .../monitoring/prometheus/node-exporter.nix | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/node-exporter.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7a74fe2d785b..a08a596a1760 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -288,6 +288,7 @@ ./services/monitoring/munin.nix ./services/monitoring/nagios.nix ./services/monitoring/prometheus/default.nix + ./services/monitoring/prometheus/node-exporter.nix ./services/monitoring/riemann.nix ./services/monitoring/riemann-dash.nix ./services/monitoring/riemann-tools.nix diff --git a/nixos/modules/services/monitoring/prometheus/node-exporter.nix b/nixos/modules/services/monitoring/prometheus/node-exporter.nix new file mode 100644 index 000000000000..a462d16eef9a --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/node-exporter.nix @@ -0,0 +1,47 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.prometheus.nodeExporter; + cmdlineArgs = cfg.extraFlags ++ [ + "-web.listen-address=${cfg.listenAddress}" + ]; +in { + options = { + services.prometheus.nodeExporter = { + enable = mkEnableOption "Enable the Prometheus node exporter (CPU stats etc)."; + listenAddress = mkOption { + type = types.str; + default = "0.0.0.0:9100"; + description = '' + Address to listen on. + ''; + }; + extraFlags = mkOption { + type = types.listOf types.str; + default = []; + description = '' + Extra commandline options when launching the node exporter. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services.prometheus-node-exporter = { + description = "Prometheus exporter for machine metrics"; + unitConfig.Documentation = "https://github.com/prometheus/node_exporter"; + wantedBy = [ "multi-user.target" ]; + script = '' + exec ${pkgs.prometheus-node-exporter}/bin/node_exporter \ + ${concatStringsSep " \\\n " cmdlineArgs} + ''; + serviceConfig = { + User = "nobody"; + Restart = "always"; + ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + }; + }; + }; +}