Skip to content

Instantly share code, notes, and snippets.

@beaufour
Last active September 11, 2019 22:01
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 beaufour/61b00ad64ed917c0e35c70466e77cc82 to your computer and use it in GitHub Desktop.
Save beaufour/61b00ad64ed917c0e35c70466e77cc82 to your computer and use it in GitHub Desktop.
Save Speedtest.net data to InfluxDB
delegator.py==0.1.1
requests==2.22.0
#!/usr/bin/env python
import argparse
import delegator
import json
import requests
def run(client_id, influx_db):
cmd = delegator.run('speedtest-cli --json')
data_text = cmd.out
data = json.loads(data_text)
data_map = {
'net_download': data['download'],
'net_upload': data['upload'],
}
db_data = []
for key, value in data_map.items():
db_data.append('%s,client_id=%s,provider=speedtest.net value=%s'
% (key, client_id, value))
db_data = '\n'.join(db_data)
requests.post(influx_db, data=db_data)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--client_id', required=True,
help='client id stored in DB with results')
parser.add_argument('-d', '--influx_db', required=True,
help='InfluxDB URI, including db etc')
args = parser.parse_args()
run(args.client_id, args.influx_db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment