Skip to content

Instantly share code, notes, and snippets.

@folkertvanheusden
Last active August 23, 2021 11:32
Show Gist options
  • Save folkertvanheusden/7fe256d665dfdee305ead711280d7c4b to your computer and use it in GitHub Desktop.
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.
#! /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