iputils: ping
Subsystems (2)
PATCH 1/1 iputils: ping
Hello,
We used to use mrtg-ping-probe perl script (http://pwo.de/projects/mrtg/)
for packetloss statistics generation in MRTG. Last time the number of monitoring hosts became high, so mrtg-ping-probe overhead became inadmissible.
Here is a patch to iputils-ss020927 that adds -m option to ping utility, which allows ping to behave like mrtg-ping-probe: print average RTT and packet loss only.
Hope, this will be useful for someone.
PS Sorry, if I chose wrong place to publish this patch.
--
Best regards,
Alexander
[---cut here---]
ping.c 2009-01-29 14:10:40.000000000 +0300 renamed from ping.c.org 2002-09-20 19:08:11.000000000 +0400 +6 -4
@@ -486,10 +486,12 @@ exit(2); } - printf("PING %s (%s) ", hostname, inet_ntoa(whereto.sin_addr)); - if (device || (options&F_STRICTSOURCE)) + if ( !(options & F_MRTGPROBE) ) { + printf("PING %s (%s) ", hostname, inet_ntoa(whereto.sin_addr)); + if (device || (options&F_STRICTSOURCE)) printf("from %s %s: ", inet_ntoa(source.sin_addr), device ?: ""); - printf("%d(%d) bytes of data.\n", datalen, datalen+8+optlen+20); + printf("%d(%d) bytes of data.\n", datalen, datalen+8+optlen+20); + } setup(icmp_sock);
@@ -1197,7 +1199,7 @@ void usage(void) { fprintf(stderr, -"Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n" +"Usage: ping [-LRUbdfnqrvVaAm] [-c count] [-i interval] [-w deadline]\n" " [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]\n" " [-M mtu discovery hint] [-S sndbuf]\n" " [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination\n");
ping_common.c 2009-01-29 14:15:24.000000000 +0300 renamed from ping_common.c.org 2002-09-20 20:02:32.000000000 +0400 +11 -0
@@ -216,6 +216,9 @@ } lingertime *= 1000; break; + case 'm': + options |= F_MRTGPROBE; + break; case 'V': printf("ping utility, iputils-ss%s\n", SNAPSHOT); exit(0);
@@ -782,8 +785,16 @@ tvsub(&tv, &start_time); + if (options & F_MRTGPROBE) { + fflush(stdout); + printf("%d\n%d\n", (unsigned long)(tsum/1000), + (int) ((((long long)(ntransmitted - nreceived)) * 100) / ntransmitted) ); + exit(!nreceived || (deadline && nreceived < npackets)); + } + putchar('\n'); fflush(stdout); + printf("--- %s ping statistics ---\n", hostname); printf("%ld packets transmitted, ", ntransmitted); printf("%ld received", nreceived);
ping_common.h 2009-01-29 14:06:40.000000000 +0300 renamed from ping_common.h.org 2002-09-20 19:08:11.000000000 +0400 +3 -2
@@ -59,6 +59,7 @@ #define F_STRICTSOURCE 0x8000 #define F_NOLOOP 0x10000 #define F_TTL 0x20000 +#define F_MRTGPROBE 0x40000 /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@@ -117,9 +118,9 @@ case 'f': case 'i': case 'w': case 'l': \ case 'S': case 'n': case 'p': case 'q': \ case 'r': case 's': case 'v': case 'L': \ -case 't': case 'A': case 'W': case 'B': +case 't': case 'A': case 'W': case 'B': case 'm': -#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:B" +#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:B:m" /*
doc/ping.sgml 2009-01-29 13:14:38.000000000 +0300 renamed from doc/ping.sgml.org 2002-09-20 16:55:50.000000000 +0400 +9 -1
@@ -14,7 +14,7 @@ <refsynopsisdiv> <cmdsynopsis> <command>ping</command> -<arg choice="opt"><option>-LRUbdfnqrvVaAB</option></arg> +<arg choice="opt"><option>-LRUbdfnqrvVaABm</option></arg> <arg choice="opt">-c <replaceable/count/</arg> <arg choice="opt">-i <replaceable/interval/</arg> <arg choice="opt">-l <replaceable/preload/</arg>
@@ -144,6 +144,14 @@ </para></listitem> </varlistentry> <varlistentry> + <term><option/-m/</term> + <listitem><para> +Behave like mrtg-ping-probe (<ulink url="http://pwo.de/projects/mrtg/">http://pwo.de/projects/mrtg/</ulink>): +print average RTT and packet loss only. Combine with <option>-q</option> to strip +header and footer. + </para></listitem> + </varlistentry> + <varlistentry> <term><option/-n/</term> <listitem><para> Numeric output only.
[---cut here---]