64 lines
1.4 KiB
Bash
64 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
# provisioned in mbps
|
|
provisioned_upload=200
|
|
provisioned_download=10
|
|
|
|
influx_url="https://influx.domain.com" # without trailing slash and with proto (http/s)
|
|
influx_db="speedtest_db"
|
|
influx_user="speedtest_user"
|
|
influx_pass="speedtest_password"
|
|
|
|
#### Starts here ####
|
|
|
|
host=$(hostname --fqdn)
|
|
|
|
|
|
#if ! command -v bc &> /dev/null
|
|
#then
|
|
# echo "bc could not be found"
|
|
# exit 1
|
|
#fi
|
|
|
|
if ! command -v jq &> /dev/null
|
|
then
|
|
echo "jq could not be found"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
if ! command -v curl &> /dev/null
|
|
then
|
|
echo "curl could not be found"
|
|
exit
|
|
fi
|
|
|
|
|
|
if ! command -v speedtest-cli &> /dev/null
|
|
then
|
|
echo "speedtest-cli could not be found"
|
|
exit
|
|
fi
|
|
|
|
data=$(speedtest-cli --json)
|
|
|
|
ping=$(jq .ping <<< "${data}")
|
|
upload=$(jq .upload <<< "${data}")
|
|
download=$(jq .download <<< "${data}")
|
|
server_name=$(jq .server.name <<< "${data}")
|
|
server_sponsor=$(jq .server.sponsor <<< "${data}")
|
|
server_id=$(jq .server.id <<< "${data}")
|
|
server_distance=$(jq .server.d <<< "${data}")
|
|
|
|
curl -XPOST "${influx_url}/write?db=${influx_db}" \
|
|
-u "${influx_user}:${influx_pass}" \
|
|
--data-binary \
|
|
"upload,host=${host} value=${upload}
|
|
download,host=${host} value=${download}
|
|
ping,host=${host} value=${ping}
|
|
server_name,host=${host} value=${server_name}
|
|
server_sponsor,host=${host} value=${server_sponsor}
|
|
server_id,host=${host} value=${server_id}
|
|
server_distance,host=${host} value=${server_distance}"
|