From: Rich Brown <richb.hanover@gmail.com>
To: cerowrt-devel <cerowrt-devel@lists.bufferbloat.net>
Subject: [Cerowrt-devel] pingstats.sh script to measure and record latency
Date: Sun, 2 Mar 2014 16:20:36 -0500 [thread overview]
Message-ID: <ECC41F19-CD87-4BD3-A24B-C82AD80160CC@gmail.com> (raw)
Here's the script that I used to measure the ping latency during RRUL, Speedtest.net, and other bandwidth tests.
Note that this script works fine under the ash shell on CeroWrt if vis the clean_up() function declaration as noted.
Enjoy!
Rich
==================================
#!/bin/sh
# pingstats.sh - Script to start pinging a host and
# produce summary of the response times after receiving a Ctl-C
# Usage: sh pingstats.sh [ host name/ip to ping ]
# If there is an option, it is treated as the name/address to ping
# Default is gstatic.com
# Copyright (c) 2014 - Rich Brown
# GPLv2
# Create temp file for ping results
PINGFILE=`mktemp /tmp/measurepings.XXXXXX` || exit 1
function clean_up { # called when Ctl-C is pressed
# clean_up() { # Use this line to declare the clean_up() function in ash, the CeroWrt shell.
# Process the ping times, and summarize the results
# grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them
# awk builds an array of those values, and prints first & last (which are min, max)
# and computes average and the median
grep "time=" < $PINGFILE | sed 's/^.*time=\([^ ]*\) ms/\1/' | sort -n | \
awk '{ arr[NR]=$1; sum+=$1; }END \
{ if (NR%2==1) med=arr[(NR+1)/2]; else med=(arr[NR/2]+arr[NR/2+1])/2; \
pc10="-"; pc90="-"; \
if (NR>=10) { ix=int(NR/10); pc10=arr[ix]; ix=int(NR*9/10);pc90=arr[ix]; }; \
printf("\nMin: %4.3f 10pct: %4.3f Avg: %4.3f Median: %4.3f 90pct: %4.3f Max: %4.3f Num pings: %d\n", arr[1], pc10, sum/NR, med, pc90, arr[NR], NR ) }'
# Perform program exit housekeeping
# NB: Ctl-C stops the associated background ping job
rm $PINGFILE
exit
}
trap clean_up SIGHUP SIGINT SIGTERM
PINGHOST="gstatic.com"
if [ $# -ne 0 ]; then
PINGHOST=$1
fi
ping $PINGHOST > $PINGFILE &
echo "Pinging $PINGHOST... Press Ctl-C to summarize results "
wait
#! /bin/sh
# Take file of pings time readings, compute & display min/max/avg
# Found awk scripts on:
# http://blog.damiles.com/2008/10/awk-calculate-mean-min-and-max/
# http://unix.stackexchange.com/questions/13731/is-there-a-way-to-get-the-min-max-median-and-average-of-a-list-of-numbers-in
# Found clean_up function on:
# http://linuxcommand.org/wss0160.php
reply other threads:[~2014-03-02 21:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.bufferbloat.net/postorius/lists/cerowrt-devel.lists.bufferbloat.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ECC41F19-CD87-4BD3-A24B-C82AD80160CC@gmail.com \
--to=richb.hanover@gmail.com \
--cc=cerowrt-devel@lists.bufferbloat.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox