from influxdb import InfluxDBClient
client = InfluxDBClient('localhost', 8086, 'study') # 连接数据库
client.create_database('example') # 创建数据库
# 待写入数据库的点组成的列表
points = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
]
client.write_points(points, database='example') # 将这些点写入指定database
# 查询刚刚写入的点
result = client.query('select value from cpu_load_short;', database='example')
print(result)
# ResultSet({'('cpu_load_short', None)': [{'time': '2009-11-10T23:00:00Z', 'value': 0.64}]})