Skip to content
Snippets Groups Projects
node.nix 1.99 KiB
Newer Older
# Prometheus common node exporter config
#
# Scope: Export platform data like CPU, memory, disk space etc. to be
#        polled by Prometheus server
# Usage: Import this to every server you want to include in the central
#        monitoring system
# See https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters

{ config, lib, pkgs, ... }:

with lib;

let
  mountsFileSystemType = fsType: {} != filterAttrs (n: v: v.fsType == fsType) config.fileSystems;

in {
  config.services.prometheus.exporters.node = {
    enable = true;
    openFirewall = true;
    firewallFilter = "-i monitoringvpn -p tcp -m tcp --dport 9100";
    port = 9100;
    # extraFlags = [ "--collector.disable-defaults" ]; # not in nixpkgs 19.09
    # Thanks https://github.com/mayflower/nixexprs/blob/master/modules/monitoring/default.nix
    enabledCollectors = [
      "arp"
      "bcache"
      "conntrack"
      "filefd"
      "logind"
      "netclass"
      "netdev"
      "netstat"
      #"rapl" # not in nixpkgs 19.09
      "sockstat"
      #"softnet" # not in nixpkgs 19.09
      "stat"
      "systemd"
      "textfile"
      "textfile.directory /run/prometheus-node-exporter"
      #"thermal_zone" # not in nixpkgs 19.09
      "time"
      #"udp_queues" # not in nixpkgs 19.09
      "uname"
      "vmstat"
    ] ++ optionals (!config.boot.isContainer) [
      "cpu"
      "cpufreq"
      "diskstats"
      "edac"
      "entropy"
      "filesystem"
      "hwmon"
      "interrupts"
      "ksmd"
      "loadavg"
      "meminfo"
      "pressure"
      "timex"
    ] ++ (
      optionals (config.services.nfs.server.enable) [ "nfsd" ]
    ) ++ (
      optionals ("" != config.boot.initrd.mdadmConf) [ "mdadm" ]
    ) ++ (
      optionals ({} != config.networking.bonds) [ "bonding" ]
    ) ++ (
      optionals (mountsFileSystemType "nfs") [ "nfs" ]
    ) ++ (
      optionals (mountsFileSystemType "xfs") [ "xfs" ]
    ) ++ (
      optionals (mountsFileSystemType "zfs" || elem "zfs" config.boot.supportedFilesystems) [ "zfs" ]
    );
  };
}