目的 : 統計每秒 bind 8 dns server query 回應次數
數據要如何抓出呢?
利用 bind8 每小時會產生的status log (Bind9 status要用其他方式抓出)
將最後兩行的某一欄位之數據抓出,
相減再除以3600(1小時)
即取得這小時內平均每秒回應次數
再用mrtg畫圖
(1)首先在named.conf 設定要記錄所有DNS Status
/etc/named.conf
logging {
channel stat {
file "/var/log/dns/stat.log" versions 6 size 1m;
print-time yes;
severity info;
};
category statistics { stat; };
};
(2)因為我不會寫太複雜的程式,所以分兩段程式來抓出數據
- dnsrq.sh (抓出每一小時query次數)
#!/usr/bin/sh
/bin/grep XSTATS /var/log/dns/stat.log | awk '{print $21}' | awk -F= '{print $2} ' > /tmp/DNSRQ
- qtimes.pl 取出最後兩個數據相減,除以3600 = 每秒鐘 query 次數
#!/usr/bin/perl
`sh /usr/local/bin/dnsrq.sh`;
open (FH,"/tmp/DNSRQ");
while (<FH>) {
chomp;
push @RQ, $_;
}
close (FH);
for($i=0;$RQ[$i];$i++) {
if ($i==0) {
$rq1=$RQ[$i];
} else {
$rq0=$RQ[$i-1];
$rq1=$RQ[$i];
}
}
$psqt=int(($rq1-$rq0)/3600);
print "$psqt\n$psqt\n22\n22\n";
(3)更改mrtg.cfg
Options[DNS]: gauge,growright,nopercent,integer,unknaszero
Target[DNS]: `/usr/local/bin/qtimes.pl`
MaxBytes[DNS]: 2500
Title[DNS]: Query DNS
Legend1[DNS]: DNS Query(Times/Sec)
Legend2[DNS]: DNS Query(Times/Sec)
LegendI[DNS]: DNS Query
LegendO[DNS]: DNS Query
YLegend[DNS]: Query per second
PageTop[DNS]: <h1>Query - DNS Server Query Times</h1>
下列是結果 , 雖然很醜 , 但讓我再花點時間 下次就可變成 rrd了
`Daily' Graph (5 Minute Average)
`Weekly' Graph (30 Minute Average)
`Monthly' Graph (2 Hour Average)