Created
May 21, 2012 23:07
-
-
Save gerhard/2765271 to your computer and use it in GitHub Desktop.
Bash script to continuously speedtest ISP connectivity, saves graphs to Librato Metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
######################################################################### CONFIG # | |
isp="VirginMedia" | |
run_every=1800 # in seconds | |
run_every_human="$(($run_every / 60)) minutes" | |
ovh="http://proof.ovh.net/files/10Mio.dat" | |
leaseweb="http://mirror.leaseweb.net/speedtest/10mb.bin" | |
thinkbroadband="http://ipv4.download.thinkbroadband.com/10MB.zip" | |
metrics_user="" | |
metrics_key="" | |
metrics_api="https://metrics-api.librato.com/v1/metrics" | |
######################################################################## UTILITY # | |
speedtest() { | |
local _destination="$2" | |
wget "$1" -O /dev/null 2>&1 | gawk -F"[( )]" -v user="$metrics_user" -v key="$metrics_key" -v api="$metrics_api" -v destination="$_destination" -v isp="$isp" ' | |
!/%/ { print } | |
/[0-9]+0%/ { | |
if (index($0, "100%") || (! index(done, $9))) { | |
done = done " " $9 | |
} | |
} | |
/MB\/s/ { speedtest_result = $4 } | |
/KB\/s/ { speedtest_result = sprintf("%.2f", $4 * 0.0009765625) } | |
END { | |
record_metric = "curl -u "user":"key" -d \"gauges[0][name]="isp"\" -d \"source="destination"\" -d \"gauges[0][value]="speedtest_result"\" -X POST "api | |
#print record_metric | |
system(record_metric) | |
close(record_metric) | |
} | |
' | |
} | |
while true | |
do | |
speedtest "$ovh" OVH | |
speedtest "$leaseweb" Leaseweb | |
speedtest "$thinkbroadband" ThinkBroadband | |
printf "%s\n" "Next run in $run_every_human" | |
printf "%75s\n" | tr " " "-" | |
sleep "$run_every" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment