Last active
August 23, 2021 11:32
-
-
Save folkertvanheusden/7fe256d665dfdee305ead711280d7c4b to your computer and use it in GitHub Desktop.
import a json into influx. need to manually create the influx-db before and also adjust username, password, url, etc.
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/python3 | |
from influxdb import InfluxDBClient | |
import json | |
import time | |
import urllib3 | |
http = urllib3.PoolManager() | |
resp = http.request('GET', 'http://www.hackerspace-gouda.nl/stats.json') | |
now = time.time() | |
data = json.loads(resp.data.decode('utf-8')) | |
points = [] | |
for key, value in data.items(): | |
point = { | |
"measurement": key, | |
"time": int(now * 1000000000), | |
"fields": { | |
"value": value | |
} | |
} | |
points.append(point) | |
client = InfluxDBClient('localhost', 8086, 'root', None, 'MyIP') | |
client.write_points(points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment