Munin

帶有損壞圖表的 munin 外掛

  • December 9, 2018

我已經修改了這個munin外掛,以便它在同一個圖表上跟踪多個值。在我的例子中,符號連結文件名是ipt_accounting_mail_web. 它的目的是跟踪 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

是否有更詳細的日誌記錄正在發生的事情?或者您能立即發現我的程式碼中的問題嗎?

您可以使用破折號將變數名稱更改為下劃線。穆寧在名字上是明智的。所以你必須使用 ‘web_in’ 而不是 ‘web-in’

引用自:https://serverfault.com/questions/943449