BIND DNS MRTG

 

從 BIND dump 出來的統計資訊如下 (不過最新版本的 BIND 它又長的完全不一樣了)

+++ Statistics Dump +++ (1364372549)
success 272949870
referral 26846823
nxrrset 48759965
nxdomain 32763784
recursion 540826
failure 6113
--- Statistics Dump --- (1364372549)

這個值是累加的

所以排程是五分鐘取一次,然後扣掉前五鐘前的值,也就等於是這五分鐘內所產生的 query 量 ,然後再除以 5 等於是平均每分鐘的量

Queryies = (success + referral + nxrrset + nxdomain + recursion + failure ) / 5

Replied = (Queries – failure ) / 5

MRTG.cfg (參考來源 : http://www.megalinux.net/dns-monitoring-using-mrtg/)

(我稍作修改)

WorkDir: /path/dns/query
Target[ssorc]: `/path/check_dns_stats.pl`
Options[ssorc]: gauge,growright,nopercent,integer,unknaszero
Title[ssorc]: DNS Server
RouterUptime[ssorc]: public@localhost
MaxBytes[ssorc]: 32000
AbsMax[ssorc]: 64000
WithPeak[ssorc]: wmy
Colours[ssorc]: YELLOW #F9C000,RED #F90000,LIGHT YELLOW #FFFFBB,LIGTH RED #FF8080
ShortLegend[ssorc]:queries/m
YLegend[ssorc]: Qs per Minute
Legend1[ssorc]: Queries received over 1 minute
Legend2[ssorc]: Replied Queries received over 1 minute
Legend3[ssorc]: Maximal Queries over 5 minutes
Legend4[ssorc]: Maximal Replied Queries over 5 minutes
LegendI[ssorc]: Queries: 
LegendO[ssorc]: Replied: 
PageTop[ssorc]: <H1>DNS Info</H1><TABLE><TR><TD>System:</TD> <TD>ssorc</TD></TR><TD>Description:</TD><TD>DNS Monitor</TD></TR><TR><TD>Details:</TD> <TD>Query Monitor</TD></TABLE>

 

check_dns_stats.pl (參考來源 : http://www.megalinux.net/dnsstats.pl)

(我稍作修改)

#!/usr/bin/perl
use strict;
# Set files to use, change these to suit your needs
my $oldstatfile = "/var/tmp/dns-old.txt";
my $newstatfile = "/var/named/data/named_stats.txt";
# Obtain old DNS stats from stored file
open(OLDF, "$oldstatfile");
my @raw_data = <OLDF>;
close(OLDF);
my $oldquery = @raw_data[0];
my $oldreply = @raw_data[1];
chomp($oldquery);
chomp($oldreply);
# Check if there is data, if not, initialize
if (! $oldquery) {
 $oldquery = 0;
}
if (! $oldreply) {
 $oldreply = 0;
}
# Get new data from file, first clean the stats file and dump new
system("cat /dev/null > $newstatfile");
system("/usr/sbin/rndc stats");
open(NEWF, "$newstatfile");
my @dns_data = <NEWF>;
close(NEWF);
my $newquery = 0;
my $newreply = 0; 
my $newfailure = 0;
foreach my $line (@dns_data) {
 if ($line =~ /^\w+ ([0-9]*)/) {
 $newquery = $newquery + $1;
 }
 if ($line =~ /^failure ([0-9]*)/) {
 $newfailure = $1;
 }
}
$newreply = $newquery - $newfailure;
# Calculate difference between old and new. Divide by 5 to get per minute
my $diffquery = ($newquery - $oldquery) / 5;
my $diffreply = ($newreply - $oldreply) / 5;
# Store new data
open(OLDF, ">$oldstatfile");
print(OLDF "$newquery\n$newreply");
close(OLDF);
# Print difference
print("$diffquery \n$diffreply \n");
Related posts 相關文章
dnscrypt-proxy 讓 DNS 查詢加密
More...
DNS BIND 9.16.50 最後一個版本已釋出
More...
DNS BIND 9.16 版本將 EOL
More...
在 Windows 上面 Plesk Obsidian 18.0.60 後不再維護 BIND DNS
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。