繼續介紹zabbix監控企業應用的實例,本次介紹zabbix監控dns,我監控的dns為bind 9.8.2,本dns為公網dns,是為了解決公司內網服務器自動化所需求的dns解析,比如目前的puppet或者salt軟件,如果結合dns,管理起來更方便,對於管理服務器來說,如果搬遷機房或者硬件出現故障,如果有dns解析,那么直接切換域名,30s內生效,這樣故障恢復的時間就會更短,總之有dns做解析的好處多多,這里就不多介紹,如何的安裝可以參考我的文章http://dl528888.blog.51cto.com/blog/2382721/1249311(centos 6.2安裝bind 9.8.2 master、slave與自動修改后更新)
一、客戶端操作
1.登陸dns部署的服務器,安裝zabbix客戶端,然后客戶端的配置文件里,比如我的是/usr/loca/zabbix/conf/zabbix_agentd.conf里添加
UserParameter=check_dns[*],/usr/bin/sudo/usr/local/zabbix/bin/zabbix_monitor_dns.sh $1
然后在cd /usr/local/zabbix/bin/
添加一個zabbix_monitor_dns.sh文件,內容為
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/bin/bash
named_stats=
'/tmp/named_stats.txt'
###++ Incoming Requests ++
Incoming_QUERY=`awk
'/QUERY/{print $1}'
$named_stats`
Incoming_RESERVED9=`awk
'/RESERVED9/{print $1}'
$named_stats`
###++ Incoming Queries ++
Incoming_A=`grep A $named_stats |awk
'NR==1{print $1}'
`
Incoming_SOA=`grep SOA $named_stats |awk
'NR==1{print $1}'
`
Incoming_PTR=`grep PTR $named_stats |awk
'NR==1{print $1}'
`
Incoming_MX=`grep MX $named_stats |awk
'NR==1{print $1}'
`
Incoming_TXT=`grep TXT $named_stats |awk
'NR==1{print $1}'
`
Incoming_AAAA=`grep AAAA $named_stats |awk
'NR==1{print $1}'
`
Incoming_A6=`grep A6 $named_stats |awk
'NR==1{print $1}'
`
Incoming_IXFR=`grep IXFR $named_stats |awk
'NR==1{print $1}'
`
Incoming_ANY=`grep ANY $named_stats |awk
'NR==1{print $1}'
`
###++ Outgoing Queries ++
Outgoing_A=`grep
"\<A\>"
$named_stats |awk
'NR==2{print $1}'
`
Outgoing_NS=`grep NS $named_stats |awk
'NR==1{print $1}'
`
Outgoing_PTR=`grep PTR $named_stats |awk
'NR==2{print $1}'
`
#Outgoing_AAAA=`grep NS $named_stats |awk
'NR==2{print $1}'
`
Outgoing_DNSKEY=`grep DNSKEY $named_stats |awk
'NR==1{print $1}'
`
Outgoing_ANY=`grep ANY $named_stats |awk
'NR==2{print $1}'
`
Outgoing_DLV=`grep DLV $named_stats |awk
'NR==2{print $1}'
`
###++ Name Server Statistics ++
Statistics_IPv4_requests=`grep
"IPv4 requests received"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_requests_received=`grep
"requests with EDNS(0) received"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_TCP_requests=`grep
"TCP requests received"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_queries_rejected=`grep
"recursive queries rejected"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_responses_sent=`grep
"responses sent"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_EDNS_sent=`grep
"responses with EDNS(0) sent"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_successful_answer=`grep
"queries resulted in successful answer"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_authoritative_answer=`grep
"queries resulted in authoritative answer"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_non_authoritative_answer=`grep
"queries resulted in non authoritative answer"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_nxrrset=`grep
"queries resulted in nxrrset"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_SERVFAIL=`grep
"queries resulted in SERVFAIL"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_NXDOMAIN=`grep
"queries resulted in NXDOMAIN"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_recursion=`grep
"queries resulted in recursion"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_received=`grep
"queries resulted in received"
$named_stats |awk
'NR==1{print $1}'
`
Statistics_dropped=`grep
"queries resulted in dropped"
$named_stats |awk
'NR==1{print $1}'
`
###++ Resolver Statistics ++
Resolver_sent=`grep
"IPv4 queries sent"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_received=`grep
"IPv4 responses received"
$named_stats |awk
'NR==1{print $1}'
`
#Resolver_NXDOMAIN_received=`grep
""
$named_stats |awk
'NR==1{print $1}'
`
#Resolver_responses_received=`sed -n
'49p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
#Resolver_delegations_received=`sed -n
'50p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
Resolver_query_retries=`grep
"query retries"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_query_timeouts=`grep
"query timeouts"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_fetches=`grep
"IPv4 NS address fetches"
$named_stats |awk
'NR==1{print $1}'
`
#Resolver_fetch_failed=`sed -n
'54p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
Resolver_validation_attempted=`grep
"DNSSEC validation attempted"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_validation_succeeded=`grep
"DNSSEC validation succeeded"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_NX_validation_succeeded=`grep
"DNSSEC NX validation succeeded"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_RTT_10ms=`grep
"queries with RTT < 10ms"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_RTT_100ms=`grep
"queries with RTT 10-100ms"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_RTT_500ms=`grep
"queries with RTT 100-500ms"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_RTT_800ms=`grep
"queries with RTT 500-800ms"
$named_stats |awk
'NR==1{print $1}'
`
Resolver_RTT_1600ms=`grep
"queries with RTT 800-1600ms"
$named_stats |awk
'NR==1{print $1}'
`
#Resolver_RTT_gt_1600ms=`sed -n
'63p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
###++ Cache DB RRsets ++
Cache_A=`grep
"\<A\>"
$named_stats |awk
'NR==3{print $1}'
`
Cache_NS=`grep
"\<NS\>"
$named_stats |awk
'NR==3{print $1}'
`
#Cache_CNAME=`sed -n
'69p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
#Cache_SOA=`sed -n
'70p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
#Cache_PTR=`sed -n
'71p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
Cache_AAAA=`grep
"\<AAAA\>"
$named_stats |awk
'NR==2{print $1}'
`
Cache_DS=`grep
"DS"
$named_stats |awk
'NR==1{print $1}'
`
Cache_RRSIG=`grep
"RRSIG"
$named_stats |awk
'NR==1{print $1}'
`
Cache_NSEC=`grep
"NSEC"
$named_stats |awk
'NR==1{print $1}'
`
Cache_DNSKEY=`grep
"DNSKEY"
$named_stats |awk
'NR==2{print $1}'
`
#Cache_AAA=`sed -n
'77p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
Cache_cDLV=`grep
"DLV"
$named_stats |awk
'NR==2{print $1}'
`
#Cache_NXDOMAIN=`sed -n
'79p'
$named_stats |sed
's/^[ \t]*//g'
|cut -d
' '
-f
1
`
###++ Socket I/O Statistics ++
Socket_UDP_opened=`grep
"UDP/IPv4 sockets opened"
$named_stats |awk
'NR==1{print $1}'
`
Socket_TCP_opened=`grep
"TCP/IPv4 sockets opened"
$named_stats |awk
'NR==1{print $1}'
`
Socket_UDP_closed=`grep
"UDP/IPv4 sockets closed"
$named_stats |awk
'NR==1{print $1}'
`
Socket_TCP_closed=`grep
" TCP/IPv4 sockets closed"
$named_stats |awk
'NR==1{print $1}'
`
Socket_UDP_established=`grep
"UDP/IPv4 connections established"
$named_stats |awk
'NR==1{print $1}'
`
Socket_TCP_established=`grep
"TCP/IPv4 connections accepted"
$named_stats |awk
'NR==1{print $1}'
`
Socket_TCP_accepted=`grep
"TCP/IPv4 recv errors"
$named_stats |awk
'NR==1{print $1}'
`
eval echo \$$
1
|
這個腳本的內容就是監控bind管理工具rndc stats產生的一個dns狀態信息文件named_stats.txt,這個文件的地址是被/etc/named.conf控制,默認是在/var/named/data目錄
此腳本給與755權限,zabbix用戶與組
1
2
|
chmod
755
/usr/bin/sudo /usr/local/zabbix/bin/zabbix_monitor_dns.sh
chown zabbix:zabbix /bin/bash /usr/local/zabbix/bin/zabbix_monitor_dns.sh
|
然后在crontab里使用root用戶添加
1
|
*/
1
* * * * /bin/bash /usr/local/zabbix/bin/monitor_dns.sh
|
/usr/local/zabbix/bin/monitor_dns.sh的內容為
1
2
3
4
5
6
7
|
#!/bin/bash
named_stats=
'/var/named/data/named_stats.txt'
if
[ -e $named_stats ];then
rm -rf $named_stats
fi
/usr/sbin/rndc stats >>/dev/
null
2
>&
1
mv $named_stats /tmp/
|
這個腳本的作用是每1分鍾運行一次rndc status命令,然后把named_stats.txt放到tmp目錄下,如果在舊目錄里已有這個文件就刪除(這樣做是因為rndc stats運行后會不斷的把信息追加到文件里,而不是覆蓋,為了統計方便才刪除舊文件,在運行命令生成新文件)
給與腳本755權限
重啟zabbix agent服務
1
2
|
ps -ef|grep zabbix|grep -v grep|awk
'{print $2}'
|xargs kill -
9
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf
|
二、zabbix服務端操作
1.在zabbix的web界面里連接監控dns模板
在web里選擇配置-模板
然后選擇導入
然后把之前下載的dns模板。
然后在選擇主機加入這個模板即可。
下面是監控的效果圖
1、dns的tcp/udp 53端口的監控
2、Incoming Requests
3、Incoming Queries
4、Outgoing Queries
5、Name Server Statistics
6、Resolver Statistics
7、Cache DB RRsets
8、Socket I/O Statistics
目前監控展示方式為增量變化,所以圖上顯示的值肯定比named_stats.txt里的少。建議還是大家自己根據需要來修改與優化,我這個只是提供一個樣例而已,模擬在附件里。
本文出自 “吟—技術交流” 博客,請務必保留此出處http://dl528888.blog.51cto.com/2382721/1341799