Save Speedtest.net data to InfluxDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delegator.py==0.1.1 | |
requests==2.22.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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