munin 插件图表损坏

munin 插件图表损坏

我已经修改了这个munin插件这样它就可以在同一张图表上跟踪多个值。我的情况中的符号链接文件名是ipt_accounting_mail_web。它的目的是跟踪网络和邮件流量,我添加了所需的iptables规则和munin配置以将其作为 root 运行。这是我的代码,仅供参考:

#!/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

如果我测试它,munin-run它就可以工作。

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

这是输出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,*

但是主图像已损坏。以下是我得到的结果:

破碎的图表

不幸的是,主日志文件中报告的错误不是很有用:

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

有没有更详细的日志来说明发生了什么?或者你能立刻发现我代码中的问题吗?

答案1

您可以将带破折号的变量名称更改为下划线。Munin 对名称很敏感。因此您必须使用“web_in”而不是“web-in”

相关内容