Create a gist now

Instantly share code, notes, and snippets.

Write data to InfluxDB
from influxdb import InfluxDBClient
import random
from time import sleep
import sys
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'metrics')
x = 0
while True:
for d in range(0, 300):
value = random.randrange(0,100)
data = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"fields": {
"value": value }
}
]
client.write_points(data)
x += 1
sleep(5)
if x == 300:
print('Done')
sys.exit(0)
@bicofino
Owner
bicofino commented Dec 1, 2015

root@f3e90ce94cf0:~# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 0.9.5.1
InfluxDB shell 0.9.5.1

drop database metrics;
create database metrics;
root@f3e90ce94cf0:~# time python3 write.py
Done

real 5m1.702s
user 0m0.700s
sys 0m0.010s
root@f3e90ce94cf0:~#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment