From a190fc436f8b3650bee31b5b8bc37a800369572a Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 9 Mar 2021 11:03:54 +0200 Subject: [PATCH 1/5] unbound_munin_: remove trailing white space --- contrib/unbound_munin_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index defca291c..3161f25e9 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -126,7 +126,7 @@ get_state ( ) { # obtain lock for fetching the state # because there is a race condition in fetching and writing to file - # see if the lock is stale, if so, take it + # see if the lock is stale, if so, take it if test -f $lock ; then pid="`cat $lock 2>&1`" kill -0 "$pid" >/dev/null 2>&1 From e1caa764b889b0d42b417866338174f3091473b3 Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 9 Mar 2021 11:09:45 +0200 Subject: [PATCH 2/5] unbound_munin_: use Munin's helper script to detect state file location --- contrib/unbound_munin_ | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index 3161f25e9..6956d09a4 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -14,7 +14,6 @@ # Run the command unbound-control-setup to generate the key files. # # Environment variables for this script -# statefile - where to put temporary statefile. # unbound_conf - where the unbound.conf file is located. # unbound_control - where to find unbound-control executable. # spoof_warn - what level to warn about spoofing @@ -24,7 +23,6 @@ # with: # [unbound*] # user root -# env.statefile /usr/local/var/munin/plugin-state/unbound-state # env.unbound_conf /usr/local/etc/unbound/unbound.conf # env.unbound_control /usr/local/sbin/unbound-control # env.spoof_warn 1000 @@ -66,7 +64,6 @@ System with unbound daemon. [unbound*] user root - env.statefile /usr/local/var/munin/plugin-state/unbound-state env.unbound_conf /usr/local/etc/unbound/unbound.conf env.unbound_control /usr/local/sbin/unbound-control env.spoof_warn 1000 @@ -98,7 +95,8 @@ BSD =cut -state=${statefile:-/usr/local/var/munin/plugin-state/unbound-state} +. ${MUNIN_LIBDIR}/plugins/plugin.sh +state="${MUNIN_PLUGSTATE}/unbound.state" conf=${unbound_conf:-/usr/local/etc/unbound/unbound.conf} ctrl=${unbound_control:-/usr/local/sbin/unbound-control} warn=${spoof_warn:-1000} From 69e215b6301ea23a8b9217497c61a4401746777d Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 9 Mar 2021 12:03:51 +0200 Subject: [PATCH 3/5] unbound_munin: fix statistics after unbound restart / server reboot "unbound-control stats" lists only query types that has been seen after unbound restart. Munin requires list of all types ever seen, or the generated graphs are mostly empty after restart. Fix this by adding a state file with list of seen query types etc. --- contrib/unbound_munin_ | 46 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index 6956d09a4..d4660f4b4 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -97,6 +97,7 @@ BSD . ${MUNIN_LIBDIR}/plugins/plugin.sh state="${MUNIN_PLUGSTATE}/unbound.state" +seentags="${MUNIN_PLUGSTATE}/unbound-seentags.state" conf=${unbound_conf:-/usr/local/etc/unbound/unbound.conf} ctrl=${unbound_control:-/usr/local/sbin/unbound-control} warn=${spoof_warn:-1000} @@ -119,6 +120,18 @@ get_value ( ) { fi } +# Update list of seen query types etc to seentags file. This is run while +# holding the lock, after the state file is updated. +update_seentags() { + tmplist="$(cat ${seentags} 2> /dev/null) +num.query.type.A +num.query.class.IN +num.query.opcode.QUERY +num.answer.rcode.NOERROR +" + (echo "${tmplist}"; grep ^num ${state} | sed -e 's/=.*//') | sort -u > ${seentags} +} + # download the state from the unbound server. get_state ( ) { # obtain lock for fetching the state @@ -166,6 +179,7 @@ get_state ( ) { rm -f $lock exit 1 fi + update_seentags rm -f $lock } @@ -282,8 +296,7 @@ if test "$1" = "config" ; then echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" echo "graph_category DNS" - for x in `grep "^num.query.type" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` + for nm in `grep "^num.query.type" $seentags`; do tp=`echo $nm | sed -e s/num.query.type.//` p_config "$nm" "$tp" "ABSOLUTE" done @@ -295,8 +308,7 @@ if test "$1" = "config" ; then echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" echo "graph_category DNS" - for x in `grep "^num.query.class" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` + for nm in `grep "^num.query.class" $seentags`; do tp=`echo $nm | sed -e s/num.query.class.//` p_config "$nm" "$tp" "ABSOLUTE" done @@ -308,8 +320,7 @@ if test "$1" = "config" ; then echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" echo "graph_category DNS" - for x in `grep "^num.query.opcode" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` + for nm in `grep "^num.query.opcode" $seentags`; do tp=`echo $nm | sed -e s/num.query.opcode.//` p_config "$nm" "$tp" "ABSOLUTE" done @@ -321,8 +332,7 @@ if test "$1" = "config" ; then echo "graph_vlabel answer packets / \${graph_period}" echo "graph_scale no" echo "graph_category DNS" - for x in `grep "^num.answer.rcode" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` + for nm in `grep "^num.answer.rcode" $seentags`; do tp=`echo $nm | sed -e s/num.answer.rcode.//` p_config "$nm" "$tp" "ABSOLUTE" done @@ -465,27 +475,23 @@ memory) done ;; by_type) - for x in `grep "^num.query.type" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` - print_value_line $nm $x + for nm in `grep "^num.query.type" $seentags`; do + print_value $nm done ;; by_class) - for x in `grep "^num.query.class" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` - print_value_line $nm $x + for nm in `grep "^num.query.class" $seentags`; do + print_value $nm done ;; by_opcode) - for x in `grep "^num.query.opcode" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` - print_value_line $nm $x + for nm in `grep "^num.query.opcode" $seentags`; do + print_value $nm done ;; by_rcode) - for x in `grep "^num.answer.rcode" $state`; do - nm=`echo $x | sed -e 's/=.*$//'` - print_value_line $nm $x + for nm in `grep "^num.answer.rcode" $seentags`; do + print_value $nm $x done print_value "num.answer.secure" print_value "num.answer.bogus" From 534a1a42c92f32c94ec478f1a74e4b5e22c2eb45 Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 9 Mar 2021 12:20:55 +0200 Subject: [PATCH 4/5] unbound_munin: Munin categories are lower case --- contrib/unbound_munin_ | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index d4660f4b4..82e6d1522 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -244,7 +244,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" for x in `grep "^thread[0-9][0-9]*\.num\.queries=" $state | sed -e 's/=.*//'`; do exist_config $x "queries handled by `basename $x .num.queries`" @@ -268,7 +268,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel number of queries" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" p_config "total.requestlist.avg" "Average size of queue on insert" "GAUGE" p_config "total.requestlist.max" "Max size of queue (in 5 min)" "GAUGE" p_config "total.requestlist.overwritten" "Number of queries replaced by new ones" "GAUGE" @@ -279,7 +279,7 @@ if test "$1" = "config" ; then echo "graph_title Unbound memory usage" echo "graph_args --base 1024 -l 0" echo "graph_vlabel memory used in bytes" - echo "graph_category DNS" + echo "graph_category dns" p_config "mem.cache.rrset" "RRset cache memory" "GAUGE" p_config "mem.cache.message" "Message cache memory" "GAUGE" p_config "mem.mod.iterator" "Iterator module memory" "GAUGE" @@ -295,7 +295,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" for nm in `grep "^num.query.type" $seentags`; do tp=`echo $nm | sed -e s/num.query.type.//` p_config "$nm" "$tp" "ABSOLUTE" @@ -307,7 +307,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" for nm in `grep "^num.query.class" $seentags`; do tp=`echo $nm | sed -e s/num.query.class.//` p_config "$nm" "$tp" "ABSOLUTE" @@ -319,7 +319,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" for nm in `grep "^num.query.opcode" $seentags`; do tp=`echo $nm | sed -e s/num.query.opcode.//` p_config "$nm" "$tp" "ABSOLUTE" @@ -331,7 +331,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel answer packets / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" for nm in `grep "^num.answer.rcode" $seentags`; do tp=`echo $nm | sed -e s/num.answer.rcode.//` p_config "$nm" "$tp" "ABSOLUTE" @@ -346,7 +346,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" p_config "num.query.flags.QR" "QR (query reply) flag" "ABSOLUTE" p_config "num.query.flags.AA" "AA (auth answer) flag" "ABSOLUTE" p_config "num.query.flags.TC" "TC (truncated) flag" "ABSOLUTE" @@ -364,7 +364,7 @@ if test "$1" = "config" ; then echo "graph_args --base 1000 -l 0" echo "graph_vlabel queries / \${graph_period}" echo "graph_scale no" - echo "graph_category DNS" + echo "graph_category dns" echo hcache.label "cache hits" echo hcache.min 0 echo hcache.type ABSOLUTE From 70a9bfda84b6b5bcc2e24806aa0d57affa588435 Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Sat, 12 Jun 2021 22:37:33 +0300 Subject: [PATCH 5/5] contrib/unbound_munin_: minor cleanup to remove two leftovers --- contrib/unbound_munin_ | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index 82e6d1522..503752758 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -95,7 +95,6 @@ BSD =cut -. ${MUNIN_LIBDIR}/plugins/plugin.sh state="${MUNIN_PLUGSTATE}/unbound.state" seentags="${MUNIN_PLUGSTATE}/unbound-seentags.state" conf=${unbound_conf:-/usr/local/etc/unbound/unbound.conf} @@ -491,7 +490,7 @@ by_opcode) ;; by_rcode) for nm in `grep "^num.answer.rcode" $seentags`; do - print_value $nm $x + print_value $nm done print_value "num.answer.secure" print_value "num.answer.bogus"