|
|
| Author |
Message |
gashalot
Joined: 07 Sep 2005 Posts: 9
|
Posted: Sat Sep 24, 2005 11:48 am Post subject: PATCH: Advanced Ping Template: accurate ping results |
|
|
After migrating from a Windows cacti host to a Linux host, I noticed that the internal ICMP ping functionality in the <cacti>/lib/ping.php library does not accurately report network latency.
In the case of my network, Cacti's homegrown ICMP ping was reporting response times of 2-3 ms for host located approximately 2500 miles away. Using the standard (dist*2)/100 latency calculation, the absolute minimum latency on this link should be approximately 60ms. I tested the same host using the native ping, and results were reported correctly.
I decided against patching <cacti>/lib/ping.php, as it includes UDP and SNMP ping functionality used to detect dead hosts during the pollinc cycle, and checking host "aliveness" does not require accurate latency data.
Instead I have modified <cacti>/scripts/ss_fping.php script to report "true" network performance and standard deviation by using the PEAR Net_Ping and Math_Stats modules.
These modules have been tested on Debian/sarge running php5, and have been validated via the script server. Note that you may need to manually install the Net_Ping and Math_Stats module. Run "pear list" on your system to determine if this is necessary.
Installation Instructions
Replace <cacti>/scripts/ss_fping.php with the file included in the library, or apply the diff.
NOTE: the Net_Ping v2.4 has a critical flaw that causes ping output on certain Linux systems to be parsed incorrectly. I have included a patched version of the Ping.php (located in the <pear>/Net folder) as well.[/b]
| Description: |
|
 Download |
| Filename: |
cacti-adv_ping-native_ping.zip |
| Filesize: |
8.24 KB |
| Downloaded: |
308 Time(s) |
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sat Sep 24, 2005 8:30 pm Post subject: |
|
|
The problem with ss_fping.php (as I see it, never tested, don't run *nix) with a Unix poller is that the php binary must have asroot privileges to create a raw socket. TCP pings to something like port 80 should work.
Otherwise, it returns bogus data after likely an error. It works AOK in Windows. It also may be issues with the timeout in the socket_set_option() call that does not appear to work 100% in various versions of PHP.
I have updated, ss_fping for the correct standard deviation and inclulded some timeout detection as there are issues when your script timeout is low and you are getting quite a bit of packet loss. I have not posted it though.
TheWitness
|
|
| Back to top |
|
 |
gashalot
Joined: 07 Sep 2005 Posts: 9
|
Posted: Sat Sep 24, 2005 11:18 pm Post subject: |
|
|
It may be a UNIX-related issue. I recently migrated from a Win2k platform, where the ss_fping worked correctly (or at least obeyed the laws of physics). Only when I switched to UNIX did I start to see suspect latency reported.
For the record, the pollers do run as root on our UNIX boxes, but they behaved strangely when using a UDP ping as well... I'm not sure what would be causing the problem.
In the future it may be worth investigating replacing the cacti homebrew ICMP with Net_Ping (after I get some of the big bugs with it patched). Not only would it eliminate a potential cause of headache (such as the physically impossible ping responses), but it would allow non-root pollers on UNIX to use ICMP when their ping executable was installed setuid (which most UNIX installations do).
Food for thought... For now the patches are working "correctly" for us once again!
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Fri Aug 18, 2006 2:10 pm Post subject: |
|
|
After applying patch, I'm having problem with the script output as shown below;
[root@ws159132 scripts]# php ss_fping.php www.yahoo.com 10 ICMP
sh: /usr/bin/cpp: No such file or directory
PHP Warning: preg_match() expects parameter 2 to be string, array given in /usr/share/pear/Net/Ping.php on line 685
Content-type: text/html
X-Powered-By: PHP/4.3.9
<br />
<b>Warning</b>: preg_match() expects parameter 2 to be string, array given in <b>/usr/share/pear/Net/Ping.php</b> on line <b>685</b><br />
min:678.1700 avg:691.8970 max:708.3660 dev:10.5956 loss:0.0000
[root@ws159132 scripts]#
The ping result now is correct however I need to remove the warning output of the script. FYI, I'm using:
CentOS release 4.3 (Final)
Cacti 0.8.6h
cactid 0.8.6f-1
Net_ping 2.4
Math_Stats
Would you please let me know how? any help would be great.
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Fri Aug 18, 2006 2:19 pm Post subject: |
|
|
Hello!
The following code is not ours although it may look similar. Don't know, never looked at it:
| Quote: | | /usr/share/pear/Net/Ping.php |
TheWitness
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Sat Aug 19, 2006 5:12 am Post subject: |
|
|
| would you please take a look at the code? I've tried many ping's script for linux but only this patch able to produce the correct output.
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sat Aug 19, 2006 11:03 am Post subject: |
|
|
Unfortunately, you are the only one to be able to resolve this bug as I do not have your system. The error is pretty clear, you just have to find out what's different and then open a bug report with the author to fix.
TheWitness
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sat Aug 19, 2006 11:05 am Post subject: |
|
|
If you are using the latest version of Cacti's builtin ping.php, you should be able to use ICMP ping BTB. In other words you should not require this hack.
TheWitness
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Sat Aug 19, 2006 11:44 am Post subject: |
|
|
Hi TheWitness! Thanks for your reply, I greatly appreciate it.
Now I've re-install my system using cacti-0.8.6h from download url http://www.cacti.net/downloads/cacti-0.8.6h.tar.gz.
The output of Cacti's builtin ping.php still incorrect. Let's see;
[root@localhost scripts]# ping -c 15 www.yahoo.com
PING www.yahoo.akadns.net (209.131.36.158) 56(84) bytes of data.
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=0 ttl=57 time=684 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=1 ttl=57 time=713 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=2 ttl=57 time=715 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=3 ttl=57 time=690 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=4 ttl=57 time=725 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=5 ttl=57 time=845 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=6 ttl=57 time=712 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=7 ttl=57 time=672 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=8 ttl=57 time=711 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=9 ttl=57 time=682 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=10 ttl=57 time=685 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=11 ttl=57 time=707 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=12 ttl=57 time=714 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=13 ttl=57 time=684 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=14 ttl=57 time=709 ms
--- www.yahoo.akadns.net ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 14249ms
rtt min/avg/max/mdev = 672.605/710.354/845.120/39.172 ms, pipe 2
[root@localhost scripts]# php -q ss_fping.php www.yahoo.com 15 ICMP
min:28.3600 avg:188.9779 max:288.9500 dev:80.4398 loss:6.6667
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sat Aug 19, 2006 2:01 pm Post subject: |
|
|
What is your host's timeout in Cacti set to?
TheWitness
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Sat Aug 19, 2006 11:30 pm Post subject: |
|
|
Host's timeout in cacti was set using default value 400 and I've fix the script to produce accurate ping result.
From the script server command line I get a result:
| Code: | [root@ws159132 scripts]# php ss_fping.php www.yahoo.com 20 ICMP
min:670.8990 avg:691.9370 max:781.2620 dev:23.2453 loss:0.0000
|
From the shell command line I get:
| Code: | [root@ws159132 scripts]# ping -c 20 www.yahoo.com
PING www.yahoo.akadns.net (209.131.36.158) 56(84) bytes of data.
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=0 ttl=57 time=692 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=1 ttl=57 time=811 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=2 ttl=57 time=702 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=3 ttl=57 time=723 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=4 ttl=57 time=694 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=5 ttl=57 time=678 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=6 ttl=57 time=700 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=7 ttl=57 time=697 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=8 ttl=57 time=692 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=9 ttl=57 time=687 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=10 ttl=57 time=840 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=11 ttl=57 time=683 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=12 ttl=57 time=698 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=13 ttl=57 time=724 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=14 ttl=57 time=686 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=15 ttl=57 time=693 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=16 ttl=57 time=687 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=17 ttl=57 time=696 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=18 ttl=57 time=700 ms
64 bytes from f1.www.vip.sp1.yahoo.com (209.131.36.158): icmp_seq=19 ttl=57 time=676 ms
--- www.yahoo.akadns.net ping statistics ---
20 packets transmitted, 20 received, 0% packet loss, time 19231ms
rtt min/avg/max/mdev = 676.180/708.408/840.360/41.201 ms, pipe 2
[root@ws159132 scripts]#
|
From cacti log I get:
| Code: | 08/19/2006 10:55:29 AM - CACTID: Poller[0] Host[11] DS[60] SS[0] SERVER: /var/www/html/scripts/ss_fping.php ss_fping www.yahoo.com 20 ICMP, output: min:680.1120 avg:698.2480 max:725.6900 dev:10.8439 loss:0.0000
|
Now the problem is with the graph that still unable to show the correct value even host's timeout has setup to 1000. any idea how to fix this?
| Description: |
|
| Filesize: |
27.43 KB |
| Viewed: |
3140 Time(s) |

|
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sun Aug 20, 2006 12:54 am Post subject: |
|
|
Not too sure yet, but I have updated lib/ping.php in SVN BRANCH_0_8_6 to reflect more accurate results if the Cacti timeout is set too low.
Here it is below as well.
TheWitness
| Description: |
|
 Download |
| Filename: |
ping.zip |
| Filesize: |
3.79 KB |
| Downloaded: |
172 Time(s) |
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Sun Aug 20, 2006 6:14 am Post subject: |
|
|
Thanks for the update. Just been replaced ping.php with the new one and seemed I got an accurate result now.
Result from script server command line:
| Code: | [root@ws159132 scripts]# php -q ss_fping.php www.yahoo.com 20 ICMP
min:665.6700 avg:758.1961 max:908.1400 dev:83.5093 loss:10.0000 |
From poller cache log:
| Code: | | 08/19/2006 05:45:23 PM - PHPSVR: Poller[0] SERVER: /var/www/html/scripts/ss_fping.php ss_fping www.yahoo.com 20 ICMP output min:673.2100 avg:702.0345 max:758.5400 dev:20.8171 loss:0.0000 |
But the graph still showing incorrect result. What else need to be fix?
| Description: |
|
| Filesize: |
28.4 KB |
| Viewed: |
3123 Time(s) |

|
|
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9691 Location: MI, USA
|
Posted: Sun Aug 20, 2006 6:51 am Post subject: |
|
|
I am embarrased to say that the RRDfile does not store results greater than 500ms. So, edit the PING Data Template and change the max value for AVG, MAX, and MIN to 10000, delete your RRDfile and you should be Ok.
TheWitness
|
|
| Back to top |
|
 |
sizulku Cacti User
Joined: 04 Nov 2002 Posts: 102 Location: ACEH
|
Posted: Sun Aug 20, 2006 10:32 am Post subject: |
|
|
| Thanks, it work now. I'm still wondering on how packet loss was calculated since on the graph I found many pkt loss but it did not appear when I'm running script from command line or poller log.
|
|
| Back to top |
|
 |
|