From 3f10f46abecc2715d3c4a69482d4b7658949a3e0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 1 Dec 2017 11:43:45 +0100 Subject: Add ping-monitor.pl Signed-off-by: Florian Pritz --- ping-monitor.pl | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 ping-monitor.pl diff --git a/ping-monitor.pl b/ping-monitor.pl new file mode 100755 index 0000000..a435cee --- /dev/null +++ b/ping-monitor.pl @@ -0,0 +1,94 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use autodie; +use Data::Dumper; +use Time::HiRes qw(time); +use Statistics::Descriptive; + +=head1 NAME +ping-monitor.pl - Live ping statistics + +=head1 SYNOPSIS + +ping-monitor.pl + +=head1 DESCRIPTION + +ping-monitor.pl provides live mean, median, standard deviation and packet loss +statistics similar to ping(8). The statistics are calculated over the last 10 +seconds by default. + +=cut + + +if (0+@ARGV < 1) { + print "usage: $0 \n"; + exit 0; +} + +my $host = $ARGV[0]; +# a value < 0.2 requires root privileges +my $frequency = 0.2; +# 10 second average +my $window_size = 10/$frequency; + +open my $ping, "-|", "ping -nDOi $frequency -W 1 $host"; + +my @history; +my $last_reply = 0; + +# ensure we are on a clean line for cleaning later +printf "\n"; + +while (<$ping>) { + next if m/^PING /; + + if (m/^\[(?[0-9.]+)\] \d+ bytes from [^:]+: icmp_seq=\d+ ttl=\d+ time=(?