[hobbit] Graphing number of references to iptables chain
Iain Conochie
iain at shihad.org
Wed Sep 5 11:30:29 CEST 2007
<snip>
Here you go. This must bu run as root so either Set UID root (bad!) or
use sudo
#!/bin/sh
SUDO=/usr/bin/sudo
IPTABLES=/usr/sbin/iptables
CHAINS="INPUT OUTPUT FORWARD"
#BBTMP=/tmp
TOUCH=/bin/touch
$TOUCH $BBTMP/packets.$$
$TOUCH $BBTMP/bytes.$$
for i in $CHAINS
do sudo $IPTABLES -L -n -v -x| grep ^"Chain $i"| awk {'print $2 " "
$6 " : " $5'}| sed s/packets,/packets/g >> $BBTMP/packets.$$
done
for i in $CHAINS
do sudo $IPTABLES -L -n -v -x| grep ^"Chain $i"| awk {'print $2 " "
$8 " : " $7'}| sed s/bytes\)/bytes/g >> $BBTMP/bytes.$$
done
echo " " >> $BBTMP/packets.$$
echo " " >> $BBTMP/bytes.$$
$BB $BBDISP "status $MACHINE.iptables green `date` IPtables output
`cat $BBTMP/packets.$$; echo; cat $BBTMP/bytes.$$`"
rm $BBTMP/packets.$$
rm $BBTMP/bytes.$$
And here is the entry for hobbitgraph.cfg
[iptables]
TITLE IP-Tables
YAXIS Bytes
DEF:Input=iptables.rrd:INPUTbytes:AVERAGE
DEF:Output=iptables.rrd:OUTPUTbytes:AVERAGE
DEF:Forward=iptables.rrd:FORWARDbytes:AVERAGE
LINE2:Input#0000FF:Input Bytes
LINE2:Output#00FF00:Output Bytes
LINE2:Forward#FF0000:Forward Bytes
COMMENT:\n
GPRINT:Input:LAST:Input \: %5.1lf%s (cur)
GPRINT:Input:MAX: \: %5.1lf%s (max)
GPRINT:Input:MIN: \: %5.1lf%s (min)
GPRINT:Input:AVERAGE: \: %5.1lf%s (avg)\n
GPRINT:Output:LAST:Output \: %5.1lf%s (cur)
GPRINT:Output:MAX: \: %5.1lf%s (max)
GPRINT:Output:MIN: \: %5.1lf%s (min)
GPRINT:Output:AVERAGE: \: %5.1lf%s (avg)\n
GPRINT:Forward:LAST:Forward \: %5.1lf%s (cur)
GPRINT:Forward:MAX: \: %5.1lf%s (max)
GPRINT:Forward:MIN: \: %5.1lf%s (min)
GPRINT:Forward:AVERAGE: \: %5.1lf%s (avg)\n
Cheers
Iain
More information about the Xymon
mailing list