Tuesday, October 18, 2011
1:24 PM

Cacti Ping Latency Graph Problem SOLVED

I was having difficulty with generating ping latency graph using Cacti in Debian 6. Being a novice in Cacti, I was not sure what was causing the "-nan" output in the ping latency graphs. It may be mentioned that I was getting bandwidth usage graph without any problem. Well, the solution is here.

Before we start with the explanation, let's check something interesting.

Debian 6

root@firefly:~# ping google.com
64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=1 ttl=53 time=303 ms

UBUNTU


sarmed@sarmed-ubuntu:~$ ping google.com
64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_seq=1 ttl=47 time=302 ms


Notice the difference in the output? Interesting, eh?

Now, to the root cause of the problem.

Cacti uses a perl script "ping.pl" for pinging a host. The graph is generated from the output of the script.

root@firefly:~# cat /usr/share/cacti/site/scripts/ping.pl
#!/usr/bin/perl
# take care for tcp:hostname or TCP:ip@
$host = $ARGV[0];
$host =~ s/tcp:/$1/gis;
open(PROCESS, "ping -c 1 $host | grep icmp_seq | grep time |");
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;
if ($2 == "") {
print "U"; # avoid cacti errors, but do not fake rrdtool stats
}elsif ($3 eq "usec") {
print $2/1000; # re-calculate in units of "ms"
}else{
print $2;
}
The output of the script was "U", incomplete output. But as we can see in the ping statistics, the output of the ping command generates "icmp_req". So modifying the script solves the problem.

root@firefly:cat /usr/share/cacti/site/scripts/ping.pl
#!/usr/bin/perl
# take care for tcp:hostname or TCP:ip@
$host = $ARGV[0];
$host =~ s/tcp:/$1/gis;
open(PROCESS, "ping -c 1 $host | grep icmp_req | grep time |");
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;
if ($2 == "") {
print "U"; # avoid cacti errors, but do not fake rrdtool stats
}elsif ($3 eq "usec") {
print $2/1000; # re-calculate in units of "ms"
}else{
print $2;
}



Sample Output:

root@firefly:~# perl  /usr/share/cacti/site/scripts/ping.pl google.com
286

There goes the output. The poller will now plot the graph at 286 milliseconds.

Problem solved.

:)


Reference: https://bugs.launchpad.net/cacti/+bug/702869

0 comments:

Post a Comment