Skip to content

Instantly share code, notes, and snippets.

@tinoadams
Last active July 31, 2021 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinoadams/3948344adf7db444358aa63caf820495 to your computer and use it in GitHub Desktop.
Save tinoadams/3948344adf7db444358aa63caf820495 to your computer and use it in GitHub Desktop.
Write results of Ookla Speedtest to InfluxDB
#!/bin/bash
set -xeo pipefail
# Get epoch
DATE="$(date +%s)"
# Set this hostname
HOSTNAME=`hostname --short`
# Set Influx host
INFLUX_HOST=localhost
INFLUX_PORT=8086
INFLUX_DB=house
tmpfile="$(mktemp /tmp/speedtest.XXXXXX)"
# Run Speedtest and write to temp file
./speedtest --progress=no --format=json -A > "$tmpfile"
# Extract data from response
download_bytes="$(jq '.download.bytes' "$tmpfile")"
upload_bytes="$(jq '.upload.bytes' "$tmpfile")"
# Send data to Influx
echo "speedtest.download,hostname=${HOSTNAME} value=${download_bytes}" | \
curl -i -XPOST "http://${INFLUX_HOST}:${INFLUX_PORT}/write?db=${INFLUX_DB}" --data-binary @-
echo "speedtest.upload,hostname=${HOSTNAME} value=${upload_bytes}" | \
curl -i -XPOST "http://${INFLUX_HOST}:${INFLUX_PORT}/write?db=${INFLUX_DB}" --data-binary @-
rm "$tmpfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment