nixos-module/collectd/default: restore ping plugin

This commit is contained in:
Astro 2021-05-27 03:25:45 +02:00
parent 57df325207
commit 92f3be552d
1 changed files with 46 additions and 27 deletions

View File

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