{ hostName, config, lib, pkgs, ... }: let hostRole = config.site.hosts.${hostName}.role; networkPort = 25826; upstreamTypesDb = pkgs.stdenv.mkDerivation { name = "types.db"; src = config.services.collectd.package.src; phases = [ "unpackPhase" "installPhase" ]; installPhase = "cp src/types.db $out"; }; customTypesDb = builtins.toFile "types.db" '' stations value:GAUGE:0:U ''; in { services.collectd = { enable = true; buildMinimalPackage = true; extraConfig = '' TypesDB "${upstreamTypesDb}" "${customTypesDb}" ''; plugins = lib.mkMerge [ { interface = ""; conntrack = ""; # TODO: dhcpcount } (lib.optionalAttrs (hostName == "stats") { 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 = '' Server "${config.site.net.serv.hosts6.dn42.stats}" "${toString networkPort}" ''; }) (lib.optionalAttrs (hostRole == "server") { irq = ""; cpu = ""; load = ""; memory = ""; swap = ""; entropy = ""; disk = ""; df = ""; processes = ""; 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 '' Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./dhcpcount.rb}" "${toString maxTimeout}" ''; }) ]; }; }