Browse Source

nixos-module/collectd: add unbound.rb

legacy
Astro 1 year ago
parent
commit
e79bb4e297
  1. 4
      nix/nixos-module/collectd/default.nix
  2. 20
      nix/nixos-module/collectd/unbound.rb
  3. 4
      nix/nixos-module/container/dnscache.nix

4
nix/nixos-module/collectd/default.nix

@ -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}"
'';
}) ];
};
}

20
nix/nixos-module/collectd/unbound.rb

@ -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

4
nix/nixos-module/container/dnscache.nix

@ -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

Loading…
Cancel
Save