#!/bin/sh RRD_PATH="/root/study/dnsquery.rrd" IMAGE_PATH="/www/htdocs/mrtg"
#DNS List host="a.dns.tw b.dns.tw 61.220.48.1 d.dns.tw ns.twnic.net e.dns.tw f.dns.tw" rrd_data="" for dns in $host do #取得 dig 最後面的所顯示的查詢時間 msec=`/bin/dig @$dns . ns | grep 'Query time' | sed -e 's/.*: \(.*\) [a-z].*/\1/'` if [ -z $msec ];then msec=-100 echo "$dns 沒有回應,請您注意"| mail MyEmail -s "$dns 無回應" fi rrd_data="$rrd_data:$msec" done now=`date +%s` echo $rrd_data rrdtool update $RRD_PATH ${now}${rrd_data}
time="day week " for t in $time do rrdtool graph $IMAGE_PATH/dnsquery-$t.jpg \ -t "DNS Query Response Time (${t}ly)" \ -w 600 -h 250 -s `date -d "-1 $t" +%s` -v "msec" -X b \ DEF:a=dnsquery.rrd:a:MAX \ DEF:b=dnsquery.rrd:b:MAX \ DEF:c=dnsquery.rrd:c:MAX \ DEF:d=dnsquery.rrd:d:MAX \ DEF:ns=dnsquery.rrd:ns:MAX \ DEF:f=dnsquery.rrd:f:MAX \ DEF:g=dnsquery.rrd:g:MAX \ CDEF:z0=-1,a,b,c,d,ns,f,g,+,+,+,+,+,+,7,/,* \ CDEF:a1=a,3000,+ \ CDEF:a11=3000,a,a,-,+ \ CDEF:b1=b,2500,+ \ CDEF:b11=2500,a,a,-,+ \ CDEF:c1=c,2000,+ \ CDEF:c11=2000,a,a,-,+ \ CDEF:d1=d,1500,+ \ CDEF:d11=1500,a,a,-,+ \ CDEF:ns1=ns,1000,+ \ CDEF:ns11=1000,a,a,-,+ \ CDEF:f1=f,500,+ \ CDEF:f11=500,a,a,-,+ \ CDEF:g1=g, \ AREA:z0#c0c0c0:"Average Response Time(msec)" \ COMMENT:"\n" \ AREA:a1#ff0000:"a.dns.tw" \ GPRINT:a:MAX:"%12.0lf" \ GPRINT:a:AVERAGE:"%12.0lf" \ GPRINT:a:MIN:"%12.0lf" \ GPRINT:a:LAST:"%12.0lf\n" \ AREA:a11#ffffff \ AREA:b1#800000:"b.dns.tw" \ GPRINT:b:MAX:"%12.0lf" \ GPRINT:b:AVERAGE:"%12.0lf" \ GPRINT:b:MIN:"%12.0lf" \ GPRINT:b:LAST:"%12.0lf\n" \ AREA:b11#ffffff \ AREA:c1#00ff00:"c.dns.tw" \ GPRINT:c:MAX:"%12.0lf" \ GPRINT:c:AVERAGE:"%12.0lf" \ GPRINT:c:MIN:"%12.0lf" \ GPRINT:c:LAST:"%12.0lf\n" \ AREA:c11#ffffff \ AREA:d1#008000:"d.dns.tw" \ GPRINT:d:MAX:"%12.0lf" \ GPRINT:d:AVERAGE:"%12.0lf" \ GPRINT:d:MIN:"%12.0lf" \ GPRINT:d:LAST:"%12.0lf\n" \ AREA:d11#ffffff \ AREA:ns1#0000ff:"ns.twnic.net" \ GPRINT:ns:MAX:"%8.0lf" \ GPRINT:ns:AVERAGE:"%12.0lf" \ GPRINT:ns:MIN:"%12.0lf" \ GPRINT:ns:LAST:"%12.0lf\n" \ AREA:ns11#ffffff \ AREA:f1#000080:"f.dns.tw" \ GPRINT:f:MAX:"%12.0lf" \ GPRINT:f:AVERAGE:"%12.0lf" \ GPRINT:f:MIN:"%12.0lf" \ GPRINT:f:LAST:"%12.0lf\n" \ AREA:f11#ffffff \ AREA:g1#ff8040:"g.dns.tw" \ GPRINT:g1:MAX:"%12.0lf" \ GPRINT:g1:AVERAGE:"%12.0lf" \ GPRINT:g1:MIN:"%12.0lf" \ GPRINT:g1:LAST:"%12.0lf\n" \ COMMENT:"note:<0 means no response\n" done
|