[rrd-users] Re: A very simple rrd graph code (ping)

Serge Maandag serge.maandag at staff.zeelandnet.nl
Wed Jun 5 16:13:19 MEST 2002


The Unix ping program has a nasty habit of hanging sometimes. If I
recall correctly, it is when there is no route to host. Net::Ping is a
bit low on information. Therefore I use fping and wrote some perl code,
see below.

Serge.

#!/usr/bin/perl

# arg1 = ping or loss
# arg2 = pingcount
# arg3 = target IP

my $mode = shift;
my $pingcount = shift;
my $ip = shift;


my ($loss, $rtt) = PingTest ($ip, $pingcount,12);

if ($mode eq "ping") {
    print $rtt;
}elsif ($mode eq "loss") {
    print $loss;
};

sub PingTest {
    my ($HostAddress, $PingCount, $BytesCount) = @_;
    my ($teller, $teller2, $rtt, $loss) = (0,0,0,0);
    my $fping = "/usr/sbin/fping";

    $cmdline=`$fping -C$PingCount -q $HostAddress -b$BytesCount 2>&1`;
    $cmdline =~ /: (.*)/; $line = $1; # filter out the packet loss
percentage
    foreach $hoi (map { split ' ' } $line) {
        $hoi =~ /-/ && do {$loss = ($loss * $teller2++ + 100) /
$teller2; } or do {
            $rtt  = ($rtt * $teller++ + $hoi) / $teller;
            $loss = ($loss * $teller2++) / $teller2;
        };
    }
    return (int($loss), int($rtt/10)); # bug in fping 2.2 -> rtt is
reported 10 times too high :(
}

-----Original Message-----
From: Matej Zerovnik - LeVaK [mailto:levak at planetq.org]
Sent: woensdag 5 juni 2002 15:54
To: rrd-users at list.ee.ethz.ch
Subject: [rrd-users] Re: A very simple rrd graph code (ping)



On Wednesday 05 June 2002 05:46, you wrote:
> ggest a very simple graph code or utility that graphs other
> host

for ping time:
#!/bin/bash
ping -n -c 3 -q HOST |grep avg |cut -d= -f2  |awk -F"/" '{print $2}' |
sed -e 
's/ms//'

and for ping loss:
#!/bin/bash
ping -c 5 HOST | tail -2 | head -1 | awk '{ print $7 "\n" $7 }' | sed
's/%//'

The scripts only gives a number.. You have to enter them into rrd
archive with 
rrdtool update... On www.rrdtool.org read how to create a rrd archive

For graps use rrdtools create image.png DEF:ds0=ping.rrd:AVERAGE 
AREA:ds0#000000 and you should get a graph...:)

LeVaK

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi


--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list