Skip to content

Instantly share code, notes, and snippets.

@beaufour
Last active Sep 11, 2019
Embed
What would you like to do?
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