2012-12-20 12:33:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Plugin to monitor Bind9 Name Server Stats
|
|
|
|
#
|
|
|
|
# Author:
|
|
|
|
# Dave Fennell <dave@microtux.co.uk>
|
|
|
|
#
|
|
|
|
# Created:
|
|
|
|
# 20th December 2012
|
|
|
|
#
|
2012-12-21 11:34:37 +01:00
|
|
|
# License:
|
2012-12-21 12:53:59 +01:00
|
|
|
# GPLv2
|
2012-12-21 11:34:37 +01:00
|
|
|
#
|
2012-12-20 12:33:07 +01:00
|
|
|
# Usage:
|
|
|
|
# Place in /etc/munin/plugins/ (or link it there using ln -s)
|
|
|
|
#
|
|
|
|
|
|
|
|
# change those to reflect your bind configuration (use plugin configuration)
|
|
|
|
# stat file
|
|
|
|
if [ "$stat_file" = "" ]; then
|
|
|
|
stat_file="/var/cache/bind/named.stats"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# rndc path
|
|
|
|
if [ "$rndc" = "" ]; then
|
|
|
|
rndc="/usr/sbin/rndc"
|
|
|
|
fi
|
|
|
|
|
2012-12-20 15:01:26 +01:00
|
|
|
# Blank the stats file (else stats are appended not replaced)
|
|
|
|
rm ${stat_file}
|
|
|
|
|
|
|
|
# Ask to bind to build new one
|
|
|
|
${rndc} stats
|
|
|
|
|
2012-12-20 12:33:07 +01:00
|
|
|
# The section we are looking for in the stats.
|
|
|
|
section="Name Server Statistics"
|
2012-12-20 15:01:26 +01:00
|
|
|
|
|
|
|
# Get all the lines in the section:
|
|
|
|
# - cat the file
|
|
|
|
# - use sed to get lines after (and excluding) the section start tag
|
|
|
|
# - use sed to get lines up to (and excluding) the next section start tag
|
|
|
|
# - use grep to remove any lines starting with a [
|
|
|
|
cmd='cat "/var/cache/bind/named.stats" | sed "0,/^\+\+ '${section}' \+\+/d" | sed -e "/^\+\+/,\$d" | grep -v "^\["'
|
2012-12-20 12:33:07 +01:00
|
|
|
|
|
|
|
# Config mode.
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
echo 'graph_args --lower-limit 0'
|
2012-12-20 15:01:26 +01:00
|
|
|
echo 'graph_category dns'
|
2012-12-20 12:33:07 +01:00
|
|
|
echo 'graph_info '${section}' for the Bind9 Name Server'
|
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_title Bind9 '${section}
|
2012-12-21 11:34:37 +01:00
|
|
|
echo 'graph_vlabel requests/${graph_period}'
|
2012-12-20 12:33:07 +01:00
|
|
|
|
|
|
|
# Output the stat configs.
|
2012-12-20 15:01:26 +01:00
|
|
|
eval ${cmd} | while read num name
|
2012-12-20 12:33:07 +01:00
|
|
|
do
|
|
|
|
# Shorten some names.
|
|
|
|
label=${name//queries resulted in /}
|
|
|
|
label=${label// answer/}
|
|
|
|
|
|
|
|
# All lowercase.
|
|
|
|
label=$(echo "$label" | tr 'A-Z' 'a-z')
|
|
|
|
|
|
|
|
# Now change names to all have no spaces.
|
|
|
|
key=${label// /_}
|
|
|
|
|
|
|
|
echo ${key}.label ${label}
|
|
|
|
echo ${key}.info ${name}
|
|
|
|
echo ${key}.type COUNTER
|
|
|
|
done
|
|
|
|
|
2018-04-07 02:11:05 +02:00
|
|
|
# If dirty config capability is enabled then fall through
|
|
|
|
# to output the data with the config information.
|
|
|
|
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
|
2012-12-20 12:33:07 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Output the stats.
|
2012-12-20 15:01:26 +01:00
|
|
|
eval ${cmd} | while read num name
|
2012-12-20 12:33:07 +01:00
|
|
|
do
|
|
|
|
# Shorten some names.
|
|
|
|
label=${name//queries resulted in /}
|
|
|
|
label=${label// answer/}
|
|
|
|
|
|
|
|
# All lowercase.
|
|
|
|
label=$(echo "$label" | tr 'A-Z' 'a-z')
|
|
|
|
|
|
|
|
# Now change names to all have no spaces.
|
|
|
|
key=${label// /_}
|
|
|
|
|
|
|
|
echo ${key}.value ${num}
|
|
|
|
done
|