#!/bin/sh # Script by Georges Rosset # to update and graph Bandwith usage # 11.05.2005 # ============================================================= # User defined variables: # ------------------------------------------ rrdfile="/datas/rrdtool/NETstats.rrd"; rrdtoolbin="/usr/local/rrdtool/bin/rrdtool"; htmldir="/WWW/utilities/net"; tempdir="/root/tmp"; bytesTXcolor=0000FF; bytesRXcolor=990000; bytesTXcolorBkgd=6666FF; bytesRXcolorBkgd=FF6666; # ------------------------------------------ # eth0TXold=$(tail $tempdir/NETstats.tmp | cut -d" " -f1); eth0RXold=$(tail $tempdir/NETstats.tmp | cut -d" " -f2); eth0TXnew=$(/root/Scripts/getNetBytes.pl | grep eth0:tx | cut -d")" -f1 | cut -d"(" -f2); eth0RXnew=$(/root/Scripts/getNetBytes.pl | grep eth0:rx | cut -d")" -f1 | cut -d"(" -f2); let eth0TX=($eth0TXnew-$eth0TXold)/300; let eth0RX=($eth0RXnew-$eth0RXold)/300; $rrdtoolbin update $rrdfile N:$eth0TX:$eth0RX:0:0; # # ========================= # Create graphs # ------------------------- # # Create 24hrs image $rrdtoolbin graph $htmldir/net.png \ --title="24 hrs variations (5 minutes average)" \ -aPNG -h200 -w600 -l0 \ DEF:bytes_TX=$rrdfile:bytesTX:LAST \ AREA:bytes_TX#$bytesTXcolorBkgd:"bytesTX/sec" \ DEF:bytes_RX=$rrdfile:bytesRX:LAST \ AREA:bytes_RX#$bytesRXcolorBkgd:"bytesRX/sec" \ LINE1:bytes_RX#$bytesRXcolor \ LINE1:bytes_TX#$bytesTXcolor \ CDEF:nodat=bytes_TX,bytes_RX,+,UN,INF,UNKN,IF \ AREA:nodat#BBBBBB:"NoData" let vruletime=$timenow-86400; # Create 7days image $rrdtoolbin graph $htmldir/net2.png \ --title="7 days variations (30 minutes average)" \ -aPNG -w600 -l0 -s-604800 \ DEF:bytes_TX=$rrdfile:bytesTX:AVERAGE \ AREA:bytes_TX#$bytesTXcolorBkgd:"bytesTX/sec" \ DEF:bytes_RX=$rrdfile:bytesRX:AVERAGE \ AREA:bytes_RX#$bytesRXcolorBkgd:"bytesRX/sec" \ LINE1:bytes_RX#$bytesRXcolor \ LINE1:bytes_TX#$bytesTXcolor \ CDEF:nodat=bytes_TX,bytes_RX,+,UN,INF,UNKN,IF \ VRULE:$vruletime#009900:"-24hrs" \ AREA:nodat#BBBBBB:"NoData" date > $htmldir/lastdate.txt echo \ \Out:\$eth0TX \<\/b\>\<\/font\> \ \In:\$eth0RX \<\/b\>\<\/font\> \ > $htmldir/laststats.txt echo $eth0TXnew $eth0RXnew > $tempdir/NETstats.tmp # ==============================================================