Cacti (home)ForumsDocumentation

Differences

This shows you the differences between two versions of the page.

manual:087:3a_advanced_topics.1_data_input_methods [2010/04/14 17:20]
gandalf removed <code> statements from images
manual:087:3a_advanced_topics.1_data_input_methods [2011/04/11 16:58] (current)
gandalf use current ping.pl
Line 63: Line 63:
  
 <code>#!/usr/bin/perl <code>#!/usr/bin/perl
-$ping `ping -c 1 $ARGV[0] | grep icmp_seq`;+ 
 +# take care for tcp:hostname or TCP:[email protected] 
 +$host $ARGV[0]; 
 +$host =~ s/tcp:/$1/gis; 
 + 
 +# old linux version use "icmp_seq" 
 +# newer use "icmp_req" instead 
 +open(PROCESS, "ping -c 1 $host | grep 'icmp_[s|r]eq' | grep time |"); 
 +$ping = <PROCESS>; 
 +close(PROCESS);
 $ping =~ m/(.*time=)(.*) (ms|usec)/; $ping =~ m/(.*time=)(.*) (ms|usec)/;
-print $2;</code>+ 
 +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; 
 +
 +</code>
  
 To define this script as a **Data Input Method** to cacti, please go to **Data Input Methods** and click **Add**. You should see: To define this script as a **Data Input Method** to cacti, please go to **Data Input Methods** and click **Add**. You should see:





Personal Tools