nixos-module/collectd: add unbound.rb

This commit is contained in:
Astro 2021-04-15 00:23:27 +02:00
parent 52cac17f16
commit e79bb4e297
3 changed files with 28 additions and 0 deletions

View File

@ -66,6 +66,10 @@ in
in ''
Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./dhcpcount.rb}" "${toString maxTimeout}"
'';
}) (lib.optionalAttrs config.services.unbound.enable {
exec = ''
Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./unbound.rb}"
'';
}) ];
};
}

View File

@ -0,0 +1,20 @@
loop do
`/run/current-system/sw/bin/unbound-control stats_noreset`
.lines
.filter { |l| l =~ /^total\./ }
.each { |l|
if l =~ /total\.(.+?)=([\d\.]+)/
name = $1
value = $2.to_f
if name =~ /\.avg$/ || name =~ /\.median$/ || name =~ /\.max$/ || name =~ /\.min$/
ty = "gauge"
else
ty = "derive"
value = value.to_i
end
puts "PUTVAL dnscache/unbound/#{ty}-#{name} N:#{value}"
end
}
sleep 10
end

View File

@ -19,6 +19,10 @@ lib.mkIf config.site.hosts.${hostName}.services.dnscache.enable {
"127.0.0.0/8"
];
extraConfig = ''
remote-control:
control-enable: yes
control-use-cert: no
forward-zone:
name: "."
forward-tls-upstream: yes