Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / dns / bind9_resolver_stats @ d79ab66b

Historique | Voir | Annoter | Télécharger (2,16 ko)

1
#!/bin/bash
2
#
3
# Plugin to monitor Bind9 Name Server Resolver Stats
4
#
5
# Author:
6
#    Dave Fennell <dave@microtux.co.uk>
7
#
8
# Created:
9
#    20th December 2012
10
#
11
# License:
12
#    GPL-2
13
#
14
# Usage:
15
#    Place in /etc/munin/plugins/ (or link it there using ln -s)
16
#
17

    
18
# change those to reflect your bind configuration (use plugin configuration)
19
# stat file
20
if [ "$stat_file" = "" ]; then
21
	stat_file="/var/cache/bind/named.stats"
22
fi
23

    
24
# rndc path
25
if [ "$rndc" = "" ]; then
26
	rndc="/usr/sbin/rndc"
27
fi
28

    
29
# Blank the stats file (else stats are appended not replaced)
30
rm ${stat_file}
31

    
32
# Ask to bind to build new one
33
${rndc} stats
34

    
35
# The section we are looking for in the stats.
36
section="Resolver Statistics"
37

    
38
# Get all the lines in the section:
39
# - cat the file
40
# - use sed to get lines after (and excluding) the section start tag
41
# - use sed to get lines up to (and excluding) the next section start tag
42
# - use grep to remove any lines starting with a [
43
cmd='cat "/var/cache/bind/named.stats" | sed "0,/^\+\+ '${section}' \+\+/d" | sed -e "/^\+\+/,\$d" | grep -v "^\["'
44

    
45
# Config mode.
46
if [ "$1" = "config" ]; then
47
	echo 'graph_args --lower-limit 0'
48
	echo 'graph_category dns'
49
	echo 'graph_info '${section}' for the Bind9 Name Server'
50
	echo 'graph_scale no'
51
	echo 'graph_title Bind9 '${section}
52
	echo 'graph_vlabel requests/${graph_period}'
53

    
54
	# Output the stat configs.
55
	eval ${cmd} | while read num name
56
	do
57
		# Shorten some names.
58
		label=${name//queries with /}
59
		label=${label//</below}
60
		label=${label//>/above}
61

    
62
		# All lowercase.
63
		label=$(echo "$label" | tr 'A-Z' 'a-z')
64

    
65
		# Now change names to all have no spaces.
66
		key=${label//[ -]/_}
67

    
68
		echo ${key}.label ${label}
69
		echo ${key}.info ${name}
70
		echo ${key}.type COUNTER
71
	done
72

    
73
	# If dirty config capability is enabled then fall through
74
	# to output the data with the config information.
75
	if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
76
		exit 0
77
	fi
78
fi
79

    
80
# Output the stats.
81
eval ${cmd} | while read num name
82
do
83
	# Shorten some names.
84
	label=${name//queries with /}
85
	label=${label//</below}
86
	label=${label//>/above}
87

    
88
	# All lowercase.
89
	label=$(echo "$label" | tr 'A-Z' 'a-z')
90

    
91
	# Now change names to all have no spaces.
92
	key=${label//[ -]/_}
93

    
94
	echo ${key}.value ${num}
95
done