Skip to content

Instantly share code, notes, and snippets.

@danilochilene
Created December 1, 2015 20:31
Show Gist options
  • Save danilochilene/4a73e40e8a0b62daceb9 to your computer and use it in GitHub Desktop.
Save danilochilene/4a73e40e8a0b62daceb9 to your computer and use it in GitHub Desktop.
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)
@danilochilene
Copy link
Author

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