CREATE DATABASE mydb
USE mydb
CREATE MEASUREMENT mymeasurement
python
import requests
data = [
{
"measurement": "mymeasurement",
"tags": {
"tag1": "value1",
"tag2": "value2"
},
"time": "2020-01-01T00:00:00Z",
"fields": {
"field1": 1.0,
"field2": 2.0
}
}
]
url = "http://localhost:8086/write?db=mydb"
requests.post(url, data="
".join(data))
python
import requests
url = "http://localhost:8086/query?db=mydb&q=SELECT * FROM mymeasurement"
response = requests.get(url)
data = response.json()
if "results" in data:
result = data["results"][0]
if "series" in result:
series = result["series"][0]
if "values" in series:
values = series["values"]
for value in values:
print(value)
python
from influxdb import InfluxDBClient
import time
client = InfluxDBClient(host='localhost', port=8086)
client.create_database('mydb')
client.switch_database('mydb')
while True:
throughput = get_throughput()
data_point = {
"measurement": "throughput",
"tags": {},
"time": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"fields": {
"value": throughput
}
}
client.write_points([data_point])
time.sleep(1)