# 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, options, ... }: with lib; let cfg = config.services.private-storage.monitoring.exporters.node; mountsFileSystemType = fsType: {} != filterAttrs (n: v: v.fsType == fsType) config.fileSystems; in { options.services.private-storage.monitoring.exporters.node = { enable = lib.mkEnableOption "Base system metrics collection"; textfiles-directory = lib.mkOption { type = lib.types.str; description = "Directory used by the textfiles collector."; default = "/run/prometheus-node-exporter"; }; }; config.services.prometheus.exporters.node = lib.mkIf cfg.enable { 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 ${cfg.textfiles-directory}" #"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" ] ); }; }