docker-entrypoint.sh 1009 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. # InfluxDB variables
  3. influxdb_proto=${INFLUXDB_PROTO:-http}
  4. influxdb_host=${INFLUXDB_HOST:-influxdb}
  5. influxdb_port=${INFLUXDB_PORT:-8086}
  6. influxdb_db=${INFLUXDB_DB:-speedtest}
  7. influxdb_url="${influxdb_proto}://${influxdb_host}:${influxdb_port}"
  8. # run speedtest & store result
  9. json_result=$(speedtest -f json --accept-license --accept-gdpr)
  10. # Extract data from speedtest result
  11. result_id=$(echo "${json_result}" | jq -r '.result.id')
  12. ping_latency=$(echo "${json_result}" | jq -r '.ping.latency')
  13. download_bandwidth=$(echo "${json_result}" | jq -r '.download.bandwidth')
  14. upload_bandwidth=$(echo "${json_result}" | jq -r '.upload.bandwidth')
  15. # Ensure InfluxDB database exists
  16. curl \
  17. -d "q=CREATE DATABASE ${influxdb_db}" \
  18. "${influxdb_url}/query"
  19. # Write metric to InfluxDB
  20. curl \
  21. -d "speedtest,result_id=${result_id} ping_latency=${ping_latency},download_bandwidth=${download_bandwidth},upload_bandwidth=${upload_bandwidth}" \
  22. "${influxdb_url}/write?db=${influxdb_db}"