Page 1 of 1

Top 10 bandwidth usage

Posted: Wed Oct 01, 2014 5:38 am
by rhassing
We have written a script that monitors bandwidth usage on a lot of different ports on a lot of different hosts. In total we have 116 servicechecks now.
All of them have an output like this: OK: RX: 1% TX: 3%
The check allows us to give information on each switchport and the bandwidth used.

Now I would like to make a top 10 of the most busiest ports.

Is there anything available to create a top 10 on service chacks?

Best regards,
Rob Hassing

Re: Top 10 bandwidth usage

Posted: Wed Oct 01, 2014 3:54 pm
by sreinhardt
Not with core by default. Are you using PNP or anything to store your performance data? You would almost definitely be able to poll those files for the needed information. You could probably rip it out of nagios logs or the last 12 checks out of retention.dat, but both of those are less than ideal solutions.

Re: Top 10 bandwidth usage

Posted: Thu Oct 02, 2014 7:10 am
by rhassing
I found a way to get the information from all rrd files:

Code: Select all

for x in /var/spool/sflow/rrd/*.rrd; do
  rrdtool graph /dev/null \
    --start -360 --end -120 --step 20 \
    DEF:bytesIn=$x:bytesIn:AVERAGE \
    CDEF:bpsIn=bytesIn,8,* \
    VDEF:bpsInmax=bpsIn,MAXIMUM \
    PRINT:bpsInmax:$x=%lf
done \
| grep = \
| sort -t= -nrk 2 \
| head -10 > /tmp/top10in.txt

Code: Select all

<?php 

echo "<h1>Top 10</h1>";
echo "<table cellpadding=0 cellspacing=0 border=0>";
echo "<tr><td>Incoming:</td></tr>";

$lines = file('/tmp/top10in.txt');
foreach ($lines as $line_num => $line) {
preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $line, $ip);
preg_match("/\d{1,3}\.rrd/", $line, $ports);
preg_match("/\d{1,3}/", $ports[0], $port);
$host = exec("grep $ip[0] /etc/hosts | awk '{print $2}'");
echo "<tr><td><a href=\"http://10.35.3.244/sflow/index.php?hostname=$host&agent=$ip[0]&if=$port[0]\">$host - $port[0]</a><br></td></tr>\n";
}
?>

Re: Top 10 bandwidth usage

Posted: Thu Oct 02, 2014 9:31 am
by tmcdonald
Thanks for sharing your solution! Did that get you everything you needed? If so I'll close the thread.

Re: Top 10 bandwidth usage

Posted: Thu Oct 02, 2014 10:43 am
by rhassing
It is working out for me, so you could close the threat.