Projet

Général

Profil

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

root / plugins / bind / bind9_server_stats @ c81c20ab

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

1
#!/bin/bash
2
#
3
# Plugin to monitor Bind9 Name Server Stats
4
#
5
# Author:
6
#    Dave Fennell <dave@microtux.co.uk>
7
#
8
# Created:
9
#    20th December 2012
10
#
11
# License:
12
#    GPLv2
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="Name Server 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 resulted in /}
59
		label=${label// answer/}
60

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

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

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

    
72
	# If dirty config capability is enabled then fall through
73
	# to output the data with the config information.
74
	if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
75
fi
76

    
77
# Output the stats.
78
eval ${cmd} | while read num name
79
do
80
	# Shorten some names.
81
	label=${name//queries resulted in /}
82
	label=${label// answer/}
83

    
84
	# All lowercase.
85
	label=$(echo "$label" | tr 'A-Z' 'a-z')
86

    
87
	# Now change names to all have no spaces.
88
	key=${label// /_}
89

    
90
	echo ${key}.value ${num}
91
done