bsinb03
Joined: 14 Aug 2006 Posts: 5
|
Posted: Wed Sep 26, 2007 7:54 am Post subject: Ping Latency Script Problem |
|
|
I am having a problem getting my script that measures packet loss and rtt on cacti. It runs fine on the command line (root) but doesn't run during a cactid poll cycle (empty result). Permissions on the script are 0777.
This is frustrating me if anybody can help me that would be great! If you need any more info I will get it.
The Script is as follows:
| Code: | #!/usr/bin/perl
$Target = $ARGV[0];
$PLCount = 4;
$Ping = "ping -l 3 -c $PLCount -i .2 -w 2 $Target |";
open(PING, $Ping) || die "roundtrip:U packetloss:U\n";
while(<PING>) {
#64 bytes from 192.168.3.1: icmp_seq=3 ttl=254 time=16.0 ms
if(/time=(\d+\.?\d*)\sms/) {
if($1 eq "<") {push(@RTValues, 0)}
else {push(@RTValues, $1)}
$PLCount--;
}
if(/(\d+)\%\spacket\sloss/) {
$PacketLoss = $1;
}
}
close(PING);
#Calculate the Average Round-Trip Time
@RTValues = sort {$a <=> $b} @RTValues; #Sorts the numbers
shift(@RTValues); #Removes the lowest number
pop(@RTValues); #Removes the highest number
while($i <= $#RTValues) {
$Average += $RTValues[$i];
$i++;
}
$values = $#RTValues + 1;
if ($values <= 0) {
$values = 1;
$PacketLoss = 100;
}
$Average = $Average / $values;
$Average = sprintf("%.4f", $Average); #Round Off Decimals
if($PacketLoss == 100 || $PLCount == 4) {$Average = "U"}
print "roundtrip $Average packetloss $PacketLoss";
|
Command line result:
| Code: |
[root@cacti ~]# perl /var/www/html/scripts/ping_latency.pl www.google.co.uk
roundtrip 23.9500 packetloss 20
[root@cacti ~]# perl /var/www/html/scripts/ping_latency.pl www.google.co.uk
roundtrip 23.9500 packetloss 33 |
Log file output is as follows:
will upload in a bit!
My server info is as follows:
| Quote: | Cacti Version - 0.8.6j
Plugin Architecture - 1.1
Poller Type - Cactid v0.8.6i
Server Info - Linux 2.6.9-55.ELsmp
Web Server - Apache/2.0.52 (CentOS)
PHP - 4.3.9
PHP Extensions - yp, xml, wddx, tokenizer, sysvshm, sysvsem, standard, sockets, shmop, session, pspell, posix, pcre, overload, mime_magic, iconv, gmp, gettext, ftp, exif, dio, dbx, dba, curl, ctype, calendar, bz2, bcmath, zlib, openssl, apache2handler, gd, mysql, snmp, eAccelerator
MySQL - 4.1.20
RRDTool - 1.2.15
SNMP - 5.1.2
PluginsNetwork Discovery (discovery - v0.7)
Error Images (errorimage - v0.1)
Host Info (hostinfo - v0.1)
Report Creator (reports - v0.1b)
Network Tools (tools - v0.2)
Update Checker (update - v0.3)
Global Plugin Settings (settings - v0.2)
PHP Network Weathermap (weathermap - v0.92)
RRD Cleaner (rrdclean - v1.1)
backups - v1.1 |
| Description: |
|
| Filesize: |
44.73 KB |
| Viewed: |
1888 Time(s) |

|
|
|