root / plugins / network / dns / bind9_resolver_stats @ d79ab66b
Historique | Voir | Annoter | Télécharger (2,16 ko)
| 1 | b7d0ef9d | Dave Fennell | #!/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 | d79ab66b | Dave Fennell | # License: |
| 12 | # GPL-2 |
||
| 13 | # |
||
| 14 | b7d0ef9d | Dave Fennell | # 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 | 8c1e0f61 | Dave Fennell | # 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 | b7d0ef9d | Dave Fennell | # The section we are looking for in the stats. |
| 36 | section="Resolver Statistics" |
||
| 37 | 8c1e0f61 | Dave Fennell | |
| 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 | b7d0ef9d | Dave Fennell | |
| 45 | # Config mode. |
||
| 46 | if [ "$1" = "config" ]; then |
||
| 47 | echo 'graph_args --lower-limit 0' |
||
| 48 | 8c1e0f61 | Dave Fennell | echo 'graph_category dns' |
| 49 | b7d0ef9d | Dave Fennell | echo 'graph_info '${section}' for the Bind9 Name Server'
|
| 50 | echo 'graph_scale no' |
||
| 51 | echo 'graph_title Bind9 '${section}
|
||
| 52 | d79ab66b | Dave Fennell | echo 'graph_vlabel requests/${graph_period}'
|
| 53 | b7d0ef9d | Dave Fennell | |
| 54 | # Output the stat configs. |
||
| 55 | 8c1e0f61 | Dave Fennell | eval ${cmd} | while read num name
|
| 56 | b7d0ef9d | Dave Fennell | 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 | d79ab66b | Dave Fennell | # 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 | b7d0ef9d | Dave Fennell | fi |
| 79 | |||
| 80 | # Output the stats. |
||
| 81 | 8c1e0f61 | Dave Fennell | eval ${cmd} | while read num name
|
| 82 | b7d0ef9d | Dave Fennell | 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 |
