我正在使用influxdb来尝试使用influxdb v4.0.0在本地influxdb上编写一些'measurements'
...
我有点困惑,因为有些地方说你使用字典或者你可以使用json和/或line协议……
从这里http://influxdb-python.readthedocs.io/en/latest/examples.html#tutorials-pandas和这里和这里https://github.com/influxdata/influxdb-python/blob/master/influxdb/client.py
第一个-使用以下命令创建DB对象:
InfluxDBClient('localhost', database='DBNAME')
第二步-用数据创建字典:
measurement = {}
measurement['measurement'] = 'energy'
measurement['tags'] = {}
measurement['fields'] = {}
measurement['tags']['MeterID'] = str(meterId)
measurement['fields']['Energy_Wh'] = str(eFrame.getReading())
第三步-推送数据到BD:
try:
self.db.write(measurement)
except Exception as e:
print e
该程序可以工作,但没有数据存储在数据库中,而我的控制台输出如下:
2017-01-11 12:41:09,741 - INFO - Saving Meter: MeterId = 09060178
u'points'
Meter-ID: 09060178 Energy Value (Wh): 10380300
{'fields': {'Energy_Wh': '10380300'}, 'tags': {'MeterID': '09060178'}, 'measurement': 'energy'}
1line logger file info
2line error/Exception
3line value returned by device
4line generated dict
(prints except logging are executed last)
我似乎找不到我为什么写错了,写错了什么,以及u'points'
错误意味着什么……有人能帮忙吗??
发布于 2017-01-11 21:52:36
您可以尝试使用以下方法(如examples中所示):
from influxdb import InfluxDBClient
client = InfluxDBClient(host, port, user, password, dbname)
client.create_database(dbname)
json_body = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
]
client.write_points(json_body)
发布于 2019-03-12 16:33:00
我建议使用Pinform库,这是一种用于InfluxDB的python ORM,可以方便地获取时间戳、字段和标签。它使用正确的函数处理读写操作。
https://stackoverflow.com/questions/41591720
复制相似问题