zabbix企業應用之bind dns監控(轉)

繼續介紹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與自動修改後更新)web

1、客戶端操做centos

1.登錄dns部署的服務器,安裝zabbix客戶端,而後客戶端的配置文件裏,好比個人是/usr/loca/zabbix/conf/zabbix_agentd.conf裏添加bash

UserParameter=check_dns[*],/usr/bin/sudo/usr/local/zabbix/bin/zabbix_monitor_dns.sh $1服務器

而後在cd /usr/local/zabbix/bin/socket

添加一個zabbix_monitor_dns.sh文件,內容爲tcp

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用戶與組fetch

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的內容爲spa

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

2、zabbix服務端操做

1.在zabbix的web界面裏鏈接監控dns模板

在web裏選擇配置-模板

而後選擇導入

而後把以前下載的dns模板。

而後在選擇主機加入這個模板便可。

下面是監控的效果圖

一、dns的tcp/udp 53端口的監控

100859933.jpg

二、Incoming Requests

100957415.jpg

三、Incoming Queries

101046790.jpg

四、Outgoing Queries

101241428.jpg

五、Name Server Statistics

101325426.jpg

六、Resolver Statistics

101508106.jpg

七、Cache DB RRsets

101605346.jpg

八、Socket I/O Statistics

101647603.jpg

目前監控展現方式爲增量變化,因此圖上顯示的值確定比named_stats.txt裏的少。建議仍是你們本身根據須要來修改與優化,我這個只是提供一個樣例而已,模擬在附件裏。

本文出自 「吟—技術交流」 博客,請務必保留此出處http://dl528888.blog.51cto.com/2382721/1341799

相關文章
相關標籤/搜索