1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-26 10:58:12 +00:00

cleaned the code and added a check

This commit is contained in:
Dju 2010-09-07 02:15:14 +02:00 committed by Steve Schnepp
parent 5d5cb34f1e
commit d9b355b48a

View file

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
# #
# #
# pure-ftpd-bw plugin # pure-ftpd plugin
# show the bandwidth used by pure-ftpd, counts the bytes sent and received
# made by Dju # made by Dju
# v1.1
# #
# commands needed: logtail - grep # commands needed: logtail - grep - awk
# #
# #
# Parameters # Parameters
@ -25,9 +25,12 @@ LOGTAIL=$(which logtail)
OFFSET_FILE=/var/lib/munin/plugin-state/pure-ftpd-bw.offset OFFSET_FILE=/var/lib/munin/plugin-state/pure-ftpd-bw.offset
[ ! -z "$LOGTAIL" -a -f $LOGTAIL -a -x $LOGTAIL ] && LT_OK=1 || LT_OK=0
if [ "$1" = "autoconf" ]; then if [ "$1" = "autoconf" ]; then
if [ -f $LOGFILE ]; then if [ -f $LOGFILE ]; then
if [ ! -z "$LOGTAIL" -a -f $LOGTAIL -a -x $LOGTAIL ]; then if [ $LT_OK -eq 1 ]; then
echo yes echo yes
exit 0 exit 0
else else
@ -40,30 +43,27 @@ if [ "$1" = "autoconf" ]; then
fi fi
fi fi
if [ "$1" = "config" ]; then
echo 'graph_title Pure Ftpd Bandwidth' if [ "$1" = "config" ]; then
echo 'graph_args --base 1000 -l 0' echo 'graph_title Pure Ftpd Bandwidth'
echo 'graph_vlabel Datas sent / received' echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel Datas sent / received'
echo 'graph_category pure-ftp' echo 'graph_category pure-ftp'
echo 'dl.label Bytes downloaded' echo 'dl.label Bytes downloaded'
echo 'ul.label Bytes uploaded' echo 'ul.label Bytes uploaded'
exit 0 exit 0
fi fi
TMP1=`mktemp` TMP1=`mktemp`
$LOGTAIL -o $OFFSET_FILE $LOGFILE | grep 'GET \|PUT ' > $TMP1 if [ -f $TMP1 ]; then
$LOGTAIL -o $OFFSET_FILE $LOGFILE | grep 'GET \|PUT ' > $TMP1
dls=$(awk '/GET / {print $9}' $TMP1) echo -n "dl.value "
dl=0 awk '/GET / {DL = DL + $NF} END {print DL}'
for d in $dls; do dl=$(expr $dl + $d); done echo -n "ul.value "
echo "dl.value ${dl}" awk '/PUT / {UL = UDL + $NF} END {print UL}'
rm $TMP1
uls=$(awk '/PUT / {print $9}' $TMP1) else
ul=0 echo "cant create temp file"
for u in $uls; do ul=$(expr $ul + $u); done exit 1
echo "ul.value ${ul}" fi
rm $TMP1