|
@@ -1,5 +1,12 @@
|
|
#!/usr/bin/env bash
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
+DEBUG=0
|
|
|
|
+if [ "$1" == "debug" ]; then
|
|
|
|
+ DEBUG=1
|
|
|
|
+ set -x
|
|
|
|
+ shift
|
|
|
|
+fi
|
|
|
|
+
|
|
# InfluxDB variables
|
|
# InfluxDB variables
|
|
influxdb_proto=${INFLUXDB_PROTO:-http}
|
|
influxdb_proto=${INFLUXDB_PROTO:-http}
|
|
influxdb_host=${INFLUXDB_HOST:-influxdb}
|
|
influxdb_host=${INFLUXDB_HOST:-influxdb}
|
|
@@ -21,15 +28,12 @@ packet_loss=$(echo "${json_result}" | jq -r '.packetLoss')
|
|
# Write metric to InfluxDB
|
|
# Write metric to InfluxDB
|
|
INFLUXDB_APPEND="speedtest,result_id=${result_id} ping_latency=${ping_latency},download_bandwidth=${download_bandwidth},upload_bandwidth=${upload_bandwidth},packet_loss=${packet_loss}"
|
|
INFLUXDB_APPEND="speedtest,result_id=${result_id} ping_latency=${ping_latency},download_bandwidth=${download_bandwidth},upload_bandwidth=${upload_bandwidth},packet_loss=${packet_loss}"
|
|
|
|
|
|
-if [ "$1" == "debug" ]; then
|
|
|
|
- echo "[DEBUG] INFLUXDB: ${INFLUXDB_APPEND}"
|
|
|
|
-else
|
|
|
|
- # Ensure InfluxDB database exists
|
|
|
|
- curl \
|
|
|
|
- -d "q=CREATE DATABASE ${influxdb_db}" \
|
|
|
|
- "${influxdb_url}/query"
|
|
|
|
-
|
|
|
|
- curl \
|
|
|
|
- -d "${INFLUXDB_APPEND}" \
|
|
|
|
- "${influxdb_url}/write?db=${influxdb_db}"
|
|
|
|
-fi
|
|
|
|
|
|
+[ ${DEBUG} -eq 1 ] && echo "[DEBUG] INFLUXDB: ${INFLUXDB_APPEND}"
|
|
|
|
+# Ensure InfluxDB database exists
|
|
|
|
+curl \
|
|
|
|
+ -d "q=CREATE DATABASE ${influxdb_db}" \
|
|
|
|
+ "${influxdb_url}/query"
|
|
|
|
+
|
|
|
|
+curl \
|
|
|
|
+ -d "${INFLUXDB_APPEND}" \
|
|
|
|
+ "${influxdb_url}/write?db=${influxdb_db}"
|