Perl script used with MRTG to graph ping times

We use MRTG extensively to graph many different things.  One of them is pinging of systems, internal and external to the University.

Here is the MRTG config section

## CSU to Google

Title[csu-google]: CSU to Google Ping Performance
Target[csu-google]: `/usr/local/mrtg-2/scripps/pingtime2.pl -c 2 google.com`
MaxBytes[csu-google]: 500
AbsMax[csu-google]: 500
Options[csu-google]: gauge, integer, growright
YLegend[csu-google]: MilliSeconds
ShortLegend[csu-google]: ms
Legend2[csu-google]:
Legend3[csu-google]:
Legend4[csu-google]:
LegendI[csu-google]: :&nbsp
LegendO[csu-google]:
Legend1[csu-google]: CSU to google in MilliSeconds
xsize[csu-google]: 600
ysize[csu-google]: 200
Colours[csu-google]: DARK GREEN#006600,DARK GREEN#006600,BLACK#000000,DARK RED#8b0000

 

Here is the script that we use (pingtime2.pl): 

#!/usr/local/bin/perl
$numtrips=0;
$trip=0;
open (IN_PING,”ping @ARGV|”);
while (<IN_PING>) {

if ($_ =~ /.+min\/avg\/max\/mdev = \d+\.\d*\/(\d+).+/) {
$trip=$trip+$1;
$numtrips=$numtrips+1;
}
}
close IN_PING;

if($numtrips) {
print int($trip/$numtrips).”\n0\n0\n0\n”;
}
else {
print “0\n0\n0\n0\n”;
}

 

Permanent link to this article: https://daherlabs.mywire.org/wordpress/?p=205

Leave a Reply

Your email address will not be published.