diff --git a/LICENSE b/LICENSE index 2d1052b..dcce9de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015, Babak Farrokhi +Copyright (c) 2017, Babak Farrokhi, Moritz Hoffmann All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 5519352..02aa8ab 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ A set of FreeBSD specific plugins for Munin - You need to install `lang/gawk` in order to run `intr_` plugin. - You need to install `sysutils/ipmitool` in order to run `ipmi_` plugin. - These are wildcard plugins, and should be installed using `munin-node-configure` program -- Some plugins such as `ipmi_` and `multiping_` need to have root access to run. +- Some plugins such as `pf_`, `ipmi_` and `multiping_` need to have root access to run. To tell Munin to run a plugin as root, adapt the following snippet and add it to `/usr/local/etc/munin/plugin-conf.d/plugins.conf`: +``` +[pf_*] +user root +``` ## Setup 1. Make sure `sysutils/munin-node` is installed diff --git a/intr_ b/intr_ index 6df0588..fac22ce 100755 --- a/intr_ +++ b/intr_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/ip_ b/ip_ index dadaa4f..fd164d8 100755 --- a/ip_ +++ b/ip_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/ipinput b/ipinput new file mode 100755 index 0000000..d60a3e9 --- /dev/null +++ b/ipinput @@ -0,0 +1,65 @@ +#!/bin/sh +# +# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# March-2017 @farrokhi +# This plugin extracts "ip input" buffer overruns using sysctl and feeds +# to munin (or any other compatible agent) for graphing +# +# Buffer overrung on IP Input happens when CPU is not fast enough +# to pick ip packet from queue. This can be observed by seeing a +# CPU hogging "task queue" process in top. +# +# Magic markers: +#%# family=auto +#%# capabilities=autoconf + + +SCRIPT_NAME=$(basename $0) + +if [ $# -lt 1 ]; then + + DROPS=`sysctl -n net.inet.ip.intr_queue_drops` + echo ip_idrops.value ${DROPS} + + +elif [ "$1" == "autoconf" ]; then + echo yes + exit 0 + +elif [ "$1" == "config" ]; then + + echo "graph_title IP Input Drops" + echo "graph_args --lower-limit 0 --base 1000" + echo "graph_vlabel packets / second" + echo "graph_category system" + + echo ip_idrops.label "Input Drops" + echo ip_idrops.type DERIVE + echo ip_idrops.min 0 + +fi + diff --git a/multiping_ b/multiping_ index eb952ff..13f1979 100755 --- a/multiping_ +++ b/multiping_ @@ -1,11 +1,11 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. -# +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions -# are met: -# +# are met: +# # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright @@ -32,43 +32,54 @@ # Configuration sample: # [multiping_*] # user root -# env.interface igb0 +# env.interface igb0:1 igb1:2 # env.hosts "4.2.2.4, ripe.net, 192.168.0.5, 8.8.4.4" # +# +# with env.interface variable, every interface should be suffixed with +# its fib number. In a normal environment, fib should always be 0. If +# you are using multiple routing tables you should use correct fib +# number (e.g. igb1 on fib 4 will be igb1:4). +# +# # Magic markers: #%# family=auto #%# capabilities=autoconf suggest SCRIPT_NAME=$(basename $0) -SRC=`echo $SCRIPT_NAME | sed -n s/multiping_//p` -PING=`which ping` || exit 1 +SRC=`echo $SCRIPT_NAME | sed -n s/multiping_//p | cut -f1 -d_` +FIB=`echo $SCRIPT_NAME | sed -n s/multiping_//p | cut -f2 -d_` +FPING=`which fping` || ( echo "fping required but not found"; exit 1) FSRC=`echo ${SRC} | sed 's/\./_/g'` -IPS=`ifconfig ${interface} | awk '/inet /{print $2}' | grep -Ev '^(10|192)\.'` +SETFIB="/usr/sbin/setfib ${FIB}" if [ $# -lt 1 ]; then - if [ x${SRC} == x ]; then + if [ -z "${SRC}" ]; then echo "should run from symlink" exit 1 fi + if [ -z "${hosts}" ]; then + echo "Unknown destination address" + exit 1 + fi + TMPFILE=`mktemp -t multiping` - for DST in `echo ${hosts} | tr , " "`; do - fname=`echo ${DST} | sed 's/\./_/g'` - ping -q -W1 -i0.1 -c10 -S ${SRC} ${DST} | sed 's/\// /g' | awk ' -/^round-trip/ { - print "rtt_'${fname}'.value " $7; -} -/ packet loss/ { - loss=$7; - gsub(/\%/, "", loss); - print "loss_'${fname}'.value " loss; + DST=`echo ${hosts} | tr , " "` + fname=`echo ${DST} | sed 's/\./_/g'` + + ${SETFIB} ${FPING} -A -q -s -i10 -c50 -p 25 -S ${SRC} -t1000 ${DST} 2>&1 | grep ':' | tr '%/,' ' ' | awk ' +/xmt/ { + name = $1; + gsub(/\./, "_", name); + printf "rtt_%s.value %0.0f\n", name, $15; + printf "loss_%s.value %0.0f\n", name, $9; } ' >> ${TMPFILE} - done - + echo "multigraph rtt_${FSRC}" grep ^rtt ${TMPFILE} echo "multigraph loss_${FSRC}" @@ -76,20 +87,28 @@ if [ $# -lt 1 ]; then rm ${TMPFILE} elif [ "$1" == "suggest" ]; then - for DST in ${IPS}; do - echo ${DST} + + # interface name format is igb0:2 - number after colon is fib number + for int in ${interface}; do + FIB=`echo ${int} | cut -f2 -d:` + NAME=`echo ${int} | cut -f1 -d:` + IPS=`ifconfig ${NAME} | grep -v tunnel | awk '/inet /{print $2}' | grep -Ev '^(10|192|127)\.'` + for DST in ${IPS}; do + echo ${DST}_${FIB} + done done + elif [ "$1" == "autoconf" ]; then - if [ x${hosts} == x ]; then + if [ -z "${hosts}" ]; then echo "no (env.hosts is not defined)" - exit 0 + exit 1 fi - if [ x${interface} == x ]; then + if [ -z "${interface}" ]; then echo "no (env.interface is not defined)" - exit 0 + exit 1 fi ### check env vars and return no if not set properly @@ -98,7 +117,7 @@ elif [ "$1" == "autoconf" ]; then elif [ "$1" == "config" ]; then - if [ x${SRC} == x ]; then + if [ -z "${SRC}" ]; then exit 1 fi @@ -107,7 +126,7 @@ elif [ "$1" == "config" ]; then echo "graph_args --lower-limit 0 --base 1000" echo "graph_vlabel milliseconds" echo "graph_category connectivity" - echo "graph_info This graph shows ICMP RTT for {$SRC} on interface ${interface} toward multiple destination hosts" + echo "graph_info This graph shows ICMP RTT for {$SRC} on FIB ${FIB} toward multiple destination hosts" COLOR=7 for DST in `echo ${hosts} | tr , " "`; do @@ -126,7 +145,7 @@ elif [ "$1" == "config" ]; then echo "graph_scale no" echo "graph_vlabel percent" echo "graph_category connectivity" - echo "graph_info This graph shows ICMP Packet Loss for source address ${SRC} on interface ${interface} toward multiple destination hosts" + echo "graph_info This graph shows ICMP Packet Loss for source address ${SRC} on FIB ${FIB} toward multiple destination hosts" COLOR=7 for DST in `echo ${hosts} | tr , " "`; do diff --git a/netirq_ b/netirq_ index 2ea9f63..7bdd910 100755 --- a/netirq_ +++ b/netirq_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -88,7 +88,8 @@ BEGIN { /'${STAT_TYPE}'/ { split($1,name,":"); - print name[1]".label "$1; + gsub(/ /,"", $1); + print name[1]".label " $1; print name[1]".type DERIVE"; print name[1]".min 0"; print name[1]".draw LINE2"; diff --git a/netisr_ b/netisr_ index 15ed699..dd73a0e 100755 --- a/netisr_ +++ b/netisr_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2017 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -46,19 +46,36 @@ if [ $# -lt 1 ]; then echo "Should run from symlink" exit 1 fi - awk ' +BEGIN { + OFS=""; + qed=0; + handled=0; + dropped=0; + hdised=0; + dised=0; + st=""; +} / ('${STAT_TYPE}') / { - print "t"$2 "_"$3"_queued.value "$9; - print "t"$2 "_"$3"_handled.value "$10; - print "t"$2 "_"$3"_dropped.value "$8; - print "t"$2 "_"$3"_hdispatched.value "$7; - print "t"$2 "_"$3"_dispatched.value "$6; -} ' ${STATFILE} + st=$3; + qed=qed+$9; + handled=handled+$10; + dropped=dropped+$8; + hdised=hdised+$7; + dised=dised+$6; +} +END { + print st, "_queued.value ", qed; + print st, "_handled.value ", handled; + print st, "_dropped.value ", dropped; + print st, "_hdispatched.value ", hdised; + print st, "_dispatched.value ", dised; +} +' ${STATFILE} elif [ "$1" == "suggest" ]; then - awk '/---/{print $1}' ${STATFILE} + awk '/--$/{print $1}' ${STATFILE} elif [ "$1" == "autoconf" ]; then ${NETSTAT} -Q >/dev/null 2>&1 && echo yes || echo no @@ -77,21 +94,21 @@ elif [ "$1" == "config" ]; then awk ' / ('${STAT_TYPE}') / { - print "t"$2 "_"$3"_queued.label Thread "$2 " Queued"; - print "t"$2 "_"$3"_handled.label Thread "$2 " Handled"; - print "t"$2 "_"$3"_dropped.label Thread "$2 " Dropped"; - print "t"$2 "_"$3"_hdispatched.label Thread "$2 " Hybrid-Dispatched"; - print "t"$2 "_"$3"_dispatched.label Thread "$2" Dispatched"; - print "t"$2 "_"$3"_queued.type DERIVE"; - print "t"$2 "_"$3"_handled.type DERIVE"; - print "t"$2 "_"$3"_dropped.type DERIVE"; - print "t"$2 "_"$3"_hdispatched.type DERIVE"; - print "t"$2 "_"$3"_dispatched.type DERIVE"; - print "t"$2 "_"$3"_queued.min 0"; - print "t"$2 "_"$3"_handled.min 0"; - print "t"$2 "_"$3"_dropped.min 0"; - print "t"$2 "_"$3"_hdispatched.min 0"; - print "t"$2 "_"$3"_dispatched.min 0"; + print $3"_queued.label Queued"; + print $3"_handled.label Handled"; + print $3"_dropped.label Dropped"; + print $3"_hdispatched.label Hybrid-Dispatched"; + print $3"_dispatched.label Dispatched"; + print $3"_queued.type DERIVE"; + print $3"_handled.type DERIVE"; + print $3"_dropped.type DERIVE"; + print $3"_hdispatched.type DERIVE"; + print $3"_dispatched.type DERIVE"; + print $3"_queued.min 0"; + print $3"_handled.min 0"; + print $3"_dropped.min 0"; + print $3"_hdispatched.min 0"; + print $3"_dispatched.min 0"; }' ${STATFILE} fi diff --git a/netmem_ b/netmem_ index 1badbfe..7e8aad9 100755 --- a/netmem_ +++ b/netmem_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/pf_ b/pf_ index 591d00b..e1f00b3 100755 --- a/pf_ +++ b/pf_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/udp_ b/udp_ index e5f54aa..a47fc2f 100755 --- a/udp_ +++ b/udp_ @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2015 Babak Farrokhi. All rights reserved. +# Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions