{ lib, config, ... }: let cfg = config.monitoring; in { config = lib.mkIf (cfg.monitorAll) { services.prometheus.exporters.node = { enable = true; port = 9100; enabledCollectors = [ #"logind" #too slow "systemd" "processes" "interrupts" # Testing: "buddyinfo" "cgroups" "ksmd" "lnstat" "mountstats" "network_route" #"perf" # requires sysctl change "qdisc" "sysctl" "softirqs" "tcpstat" ]; disabledCollectors = [ "textfile" "xfs" "zfs" "selinux" "cpufreq" "btrfs" "powersupplyclass" "mdadm" "tapestats" "fibrechannel" "cpu_vulnerabilities" "watchdog" "thermal_zone" "logind" "nfs" "nfsd" "infiniband" ]; }; services.prometheus.scrapeConfigs = ( lib.map (interval: { job_name = "node-${toString interval}s"; scrape_interval = "${toString interval}s"; static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; } ]; }) cfg.prometheusScrapeIntervals ); services.grafana.provision.dashboards.settings = { apiVersion = 1; providers = [ { name = "default"; orgId = 1; type = "file"; options = { path = builtins.fetchurl { url = "https://grafana.com/api/dashboards/1860/revisions/37/download"; sha256 = "0qza4j8lywrj08bqbww52dgh2p2b9rkhq5p313g72i57lrlkacfl"; }; }; } ]; }; }; }