Skip to content

Instantly share code, notes, and snippets.

@jeremyvisser
Created March 18, 2013 03:50
Show Gist options
  • Save jeremyvisser/5184955 to your computer and use it in GitHub Desktop.
Save jeremyvisser/5184955 to your computer and use it in GitHub Desktop.
Simple speed logging used for graphing variation. Log output is tab-delimited, which is very easy to put into a spreadsheet and turn into a graph. Logrotate is used to e-mail results daily.
# file: /etc/cron.d/speedtest
* * * * * root /usr/local/bin/speedtest 2>/dev/null >>/var/log/speedtest.log
# file: /etc/logrotate.d/speedtest
/var/log/speedtest.log {
missingok
notifempty
daily
rotate 30
create 0644 root root
prerotate
echo "Timestamp Secs Mbit/s" | cat - /var/log/speedtest.log | mail -s 'Speed test results' myself@example.com
endscript
}
#!/bin/bash
# file: /usr/local/bin/speedtest
set -e
pgrep '^nc$' >/dev/null && pkill '^nc$'
DATE=`date '+%Y-%m-%d %H:%M:%S'`
DURATION=`/usr/bin/time -f '%e' nc speedtest.mydomain.com 8888 2>&1 >/dev/zero`
# Size is assumed to be 10MB worth of \0's
RATE=`echo "scale=2; 10/$DURATION*8" | bc -l`
echo "Timestamp Secs Mbit/s" >/dev/fd/2
echo "$DATE $DURATION $RATE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment