Skip to content

Instantly share code, notes, and snippets.

@shadone
Created February 6, 2016 23:03
Show Gist options
  • Save shadone/e75f5e2b30a7317201ff to your computer and use it in GitHub Desktop.
Save shadone/e75f5e2b30a7317201ff to your computer and use it in GitHub Desktop.
Send speedtest.net results to influxdb
#!/bin/bash
INFLUXDB_HOST="localhost"
INFLUXDB_PORT="8086"
DATABASE="home"
[ -f /etc/default/speedtest_tester ] && . /etc/default/speedtest_tester
while [[ $# > 0 ]]; do
key="$1"
case $key in
-p|--port)
INFLUXDB_PORT="$2"
shift
;;
-h|--host)
INFLUXDB_HOST="$2"
shift
;;
--database)
DATABASE="$2"
shift
;;
*)
echo "Unknown option $key"
;;
esac
shift
done
timestamp=$(date +%s%N)
output=$(speedtest_cli.py --simple)
hostname=$(hostname)
line=$(echo -n "$output" | awk '/Ping/ {print "ping=" $2} /Download/ {print "download=" $2 * 1000 * 1000} /Upload/ {print "upload=" $2 * 1000 * 1000}' | tr '\n' ',' | head -c -1)
curl -XPOST "http://$INFLUXDB_HOST:$INFLUXDB_PORT/write?db=$DATABASE" -d "speedtest,host=$hostname $line $timestamp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment