From 69e215b6301ea23a8b9217497c61a4401746777d Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 9 Mar 2021 12:03:51 +0200 Subject: [PATCH] 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" -- 2.47.2