Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

node.nix

  • node.nix 2.35 KiB
    # 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" # is broken in 1.7.0 (2024-02-07)
          "bcache"
          "conntrack"
          "filefd"
          "logind"
          "netclass"
          "netdev"
          "netstat"
          "rapl"
          "sockstat"
          "softnet"
          "stat"
          "systemd"
          "textfile"
          "textfile.directory ${cfg.textfiles-directory}"
          "thermal_zone"
          "time"
          "udp_queues"
          "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" ]