0

I've modified this munin plugin so that it tracks multiple values on the same graph. The symbolic link file name in my case is ipt_accounting_mail_web. Its purpose is to track both web and mail traffic, and I added the needed iptables rules and munin configuration to run it as root. Here is my code, just for reference:

#!/bin/sh
#
# iptables Accounting Tool - based on ipt_accounting_ by Markus Frosch aka lazyfrosch
#
# See comments in original version for instructions
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf suggest

if [ "$2" = "debug" ] ; then
    set -x
fi

ACCS=`basename $0 | sed s/^ipt_accounting_//g`

if [ "$1" = "autoconf" ]; then
        if [ -r /proc/net/dev ]; then
                iptables -L INPUT -v -n -x -w >/dev/null 2>/dev/null
                if [ $? -gt 0 ]; then
                        echo "no (could not run iptables as user `whoami`)"
                else
                        echo yes
                fi
        else
                echo "no (/proc/net/dev not found)"
        fi
        exit 0
fi

if [ "$1" = "suggest" ]; then
    iptables -L INPUT -v -x -n -w 2>/dev/null | sed -n 's/^.*\/\* ACC\-\([a-zA-Z]*\) \*\/.*$/\1/p' | sort | uniq
        exit 0
fi

if [ "$1" = "config" ]; then

        echo -n "graph_order "
    for ACC in $(echo "$ACCS" | tr '_' ' ') ; do
        echo -n $ACC-out" "$ACC-in" "
    done
    echo
    echo "graph_title iptables traffic for $(echo $ACCS | sed -e 's/_/,/g')"
#        echo graph_args --base 1000
        echo graph_vlabel bytes
        echo graph_category network
    for ACC in $(echo "$ACCS" | tr '_' ' ') ; do
          echo $ACC-out.label $ACC-sent
          echo $ACC-out.type DERIVE
          echo $ACC-out.min 0
          echo $ACC-out.cdef $ACC-out,8,*
          echo $ACC-in.label $ACC-recv
          echo $ACC-in.type DERIVE
          echo $ACC-in.min 0
          echo $ACC-in.cdef $ACC-in,8,*
    done
        exit 0
fi;

for ACC in $(echo "$ACCS" | tr '_' ' ') ; do
  iptables -L INPUT -v -n -x -w | grep "\/\* ACC\-"$ACC" \*\/" | awk "{s+=\$2} END { printf \"$ACC-in.value %.0f\\n\", s}"
  iptables -L OUTPUT -v -n -x -w | grep "\/\* ACC\-"$ACC" \*\/" | awk "{s+=\$2} END { printf \"$ACC-out.value %.0f\\n\", s}"
done

If I test it through munin-run it works.

root@m-node:~# munin-run ipt_accounting_mail_web
mail-in.value 3120
mail-out.value 760
web-in.value 23273
web-out.value 357000

This is the output of munin-run ipt_accounting_mail_web config:

root@m-node:~# munin-run ipt_accounting_mail_web config
graph_order mail-out mail-in web-out web-in 
graph_title iptables traffic for mail,web
graph_vlabel bytes
graph_category network
mail-out.label mail-sent
mail-out.type DERIVE
mail-out.min 0
mail-out.cdef mail-out,8,*
mail-in.label mail-recv
mail-in.type DERIVE
mail-in.min 0
mail-in.cdef mail-in,8,*
web-out.label web-sent
web-out.type DERIVE
web-out.min 0
web-out.cdef web-out,8,*
web-in.label web-recv
web-in.type DERIVE
web-in.min 0
web-in.cdef web-in,8,*

However on the master images are broken. Here is what I get:

broken graphs

Unfortunately the error reported in the master logfile is not very useful:

root@controlpanels:/var/log/munin# cat munin-cgi-graph.log | tail -n1
2018/12/08 10:26:22 [WARNING] Could not draw graph "/var/lib/munin/cgi-tmp/munin-cgi-graph/m-node/m-node/ipt_accounting_mail_web-pinpoint=1544153129,1544261129.png?&lower_limit=&upper_limit=&size_x=800&size_y=400": /var/lib/munin/cgi-tmp/munin-cgi-graph/m-node/m-node/ipt_accounting_mail_web-pinpoint=1544153129,1544261129.png?&lower_limit=&upper_limit=&size_x=800&size_y=400

Are there more detailed logs of what's going on? Or can you spot the problem in my code right away?

Lucio Crusca
  • 420
  • 3
  • 12
  • 33
  • Could you add the result of "munin-run ipt_accounting_mail_web config" ? – Dom Dec 08 '18 at 17:18
  • 1
    The only idea I have is that the dash in variable names may be forbidden. Could you update the script to see if you can use "web_in" instead of "web-in" (and other of course) ? – Dom Dec 09 '18 at 08:54
  • Replacing dashes with underscores does it. If you turn your comment into an answer I can accept it, thanks! – Lucio Crusca Dec 09 '18 at 09:14

1 Answers1

1

You can change the variables names with a dash to an underscore. Munin is sensible on the names. So you must use 'web_in' instead of 'web-in'

Dom
  • 6,743
  • 1
  • 20
  • 24