diff --git a/monitoring/collectd/scripts/unbound-collectd/README.md b/monitoring/collectd/scripts/unbound-collectd/README.md new file mode 100644 index 0000000..405e30a --- /dev/null +++ b/monitoring/collectd/scripts/unbound-collectd/README.md @@ -0,0 +1,7 @@ +# unbound-collectd.sh +Simple script to monitor unbound + +# Prerequisites + * Unbound + * `/etc/unbound/*.key` and `/etc/unbound/*.pem` should have group unbound + * exec section should execute the script with user unbound diff --git a/monitoring/collectd/scripts/unbound-collectd/unbound-collectd.sh b/monitoring/collectd/scripts/unbound-collectd/unbound-collectd.sh new file mode 100644 index 0000000..4413a57 --- /dev/null +++ b/monitoring/collectd/scripts/unbound-collectd/unbound-collectd.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# simple script to monitor unbound +# All metrics are gauges + +HOSTNAME="${COLLECTD_HOSTNAME:-eric}" +INTERVAL="${COLLECTD_INTERVAL:-10}" + +while sleep "$INTERVAL"; do + /usr/sbin/unbound-control stats | while read line;do + INSTANCE=`echo $line | cut -d= -f1 | cut -d. -f1` + STAT=`echo $line | cut -d= -f1 | cut -d. -f2- \ + | sed 's/\./-/g' | sed 's/recursion-time-/recursion-time_/g' \ + | sed 's/now/time-now/g' | sed 's/up/time-up/g' \ + | sed 's/elapsed/time-elapsed/g' ` + VALUE=`echo $line | cut -d= -f2` + + echo "PUTVAL \"$HOSTNAME/unbound-${INSTANCE}/$STAT\" interval=$INTERVAL N:$VALUE" + done +done diff --git a/monitoring/collectd/server/collectd.conf b/monitoring/collectd/server/collectd.conf index f2712b6..8e1f897 100644 --- a/monitoring/collectd/server/collectd.conf +++ b/monitoring/collectd/server/collectd.conf @@ -223,6 +223,20 @@ LoadPlugin snmp +# monitor unbound by exec +LoadPlugin exec + + Exec "unbound" "/usr/local/bin/unbound-collectd.sh" + + +# See collectd.conf(5) +LoadPlugin unixsock + + SocketFile "/tmp/collectd.sock" + SocketGroup "nagios" + SocketPerms "0770" + + # and finaly save the data in graphite LoadPlugin write_graphite