diff --git a/nix/nixos-module/collectd/default.nix b/nix/nixos-module/collectd/default.nix index e54c762..10c7f6b 100644 --- a/nix/nixos-module/collectd/default.nix +++ b/nix/nixos-module/collectd/default.nix @@ -13,6 +13,9 @@ let customTypesDb = builtins.toFile "types.db" '' stations value:GAUGE:0:U ''; + isUpstream = + builtins.match "upstream.*" hostName != null || + builtins.match "anon.*" hostName != null; hasStarlink = builtins.any ({ upstream, ... }: if upstream == null @@ -21,7 +24,7 @@ let ) (builtins.attrValues config.site.hosts.${hostName}.interfaces); in { - services.collectd = { + services.collectd = lib.mkMerge [ { enable = true; buildMinimalPackage = true; @@ -29,22 +32,24 @@ in TypesDB "${upstreamTypesDb}" "${customTypesDb}" ''; - plugins = lib.mkMerge [ { + plugins = { interface = ""; conntrack = ""; # TODO: dhcpcount - } (lib.optionalAttrs (hostName == "stats") { - network = '' + }; + } (lib.optionalAttrs (hostName == "stats") { + plugins.network = '' Listen "::" "${toString networkPort}" Forward true Server "${config.site.net.serv.hosts4.spaceapi}" "${toString networkPort}" Server "${config.site.net.serv.hosts4.grafana}" "${toString networkPort}" ''; - }) (lib.optionalAttrs (hostName != "stats") { - network = '' + }) (lib.optionalAttrs (hostName != "stats") { + plugins.network = '' Server "${config.site.net.serv.hosts6.dn42.stats}" "${toString networkPort}" ''; - }) (lib.optionalAttrs (hostRole == "server") { + }) (lib.optionalAttrs (hostRole == "server") { + plugins = { irq = ""; cpu = ""; load = ""; @@ -57,30 +62,44 @@ in hddtemp = ""; sensors = ""; thermal = ""; - }) (lib.optionalAttrs config.services.dhcpd4.enable { - exec = - let - maxTimeout = builtins.foldl' (maxTimeout: net: - let - dhcpConf = config.site.net.${net}.dhcp; - in - if dhcpConf != null && - dhcpConf.server == hostName && - dhcpConf.time > maxTimeout - then dhcpConf.time - else maxTimeout - ) 180 (builtins.attrNames config.site.net); - in '' + }; + }) (lib.optionalAttrs isUpstream { + user = "root"; + plugins.ping = '' + Interval 10 + Timeout 1 + Size 0 + MaxMissed 100 + Host "8.8.8.8" + Host "2001:4860:4860::8888" + Host "ip5886d7b6.static.kabel-deutschland.de" + Host "r.njalla.net" + Host "inbert.c3d2.de" + Host "heise.de" + ''; + }) (lib.optionalAttrs config.services.dhcpd4.enable { + plugins.exec = + let + maxTimeout = builtins.foldl' (maxTimeout: net: + let + dhcpConf = config.site.net.${net}.dhcp; + in + if dhcpConf != null && + dhcpConf.server == hostName && + dhcpConf.time > maxTimeout + then dhcpConf.time + else maxTimeout + ) 180 (builtins.attrNames config.site.net); + in '' Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./dhcpcount.rb}" "${toString maxTimeout}" ''; - }) (lib.optionalAttrs config.services.unbound.enable { - exec = '' + }) (lib.optionalAttrs config.services.unbound.enable { + plugins.exec = '' Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./unbound.rb}" ''; - }) (lib.optionalAttrs hasStarlink { - exec = '' + }) (lib.optionalAttrs hasStarlink { + plugins.exec = '' Exec "collectd" "${self.packages.${system}.starlink-stats}/bin/starlink-stats" "192.168.100.1:9200" ''; - }) ]; - }; + }) ]; }