Last active
July 31, 2021 02:02
-
-
Save tinoadams/3948344adf7db444358aa63caf820495 to your computer and use it in GitHub Desktop.
Write results of Ookla Speedtest to InfluxDB
This file contains 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
#!/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