[rrd-users] Can this script be optimised ?

Simon Hobson linux at thehobsons.co.uk
Wed Nov 28 13:23:58 CET 2012

I've just replaced an old (now broken) 1U rackmount server that was 
running a router with a small system (Alix2, 500MHz AMD Geode). I've 
been looking at other stuff (in particular, taking great care with 
efficiency of TC filters) - this script seems to take a fair bit of 
resource, can anyone see any optimisation I've missed ?

It's getting the outside interface byte count from the "RX 
bytes:669179382 (638.1 MiB)  TX bytes:2259193189 (2.1 GiB) " line 
output by ifconfig. And updating a remote RRD every 2 seconds 
(approx). The script is started by cron every minute, and exits 
before the next minute starts.

# Get traffic count from interface counters of global interface

EndTime=$(( `/bin/date +%s` + 58 ))
HostName=$( /usr/bin/head -1 /etc/hostname )
while [ $( /bin/date +%s ) -lt ${EndTime} ]
   UpdateVal=$( /sbin/ifconfig ethext | \
     /bin/grep 'RX bytes' | \
     /bin/sed -r -e 's/^.*RX bytes:([0-9]+) .* TX bytes:([0-9]+) .*$/\1:\2/' )
   /usr/bin/rrdtool update ${HostName}/global.rrd --daemon w.x.y.z 
   sleep 2
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

More information about the rrd-users mailing list