Amm*_*mad 2 python influxdb influxdb-python
我正在使用 InfluxDb 并具有简单的线路协议行,如下所示:
cpu,atag=test1 idle=100,usertime=10,system=1
Run Code Online (Sandbox Code Playgroud)
我有使用字典的 python 客户端,如下所示
client = InfluxDBClient(host, port, USER, PASSWORD, DBNAME)
client.create_database(DBNAME)
tagdic= {'Name': 'n1', 'data': 7}
fielddic= {'Name': 'field', 'f1': 70}
def main():
var = 1
while var == 1 :
client.write("cpu,atag=test1 idle=100,usertime=10,system=1")
#client.write_points([{"measurement": "cpu", "tags": tagdic, "fields": fielddic}])
Run Code Online (Sandbox Code Playgroud)
只要我使用 write_points 和字典来使用 write_points,上面的程序就可以正常工作,但是当我使用 client.write 时出现错误。
我如何 通过使用协议值 = 'line' 而不是默认协议 'json' 来使用这里提到的 client.write (行号 -255)?
你有什么错误?这是非常重要的信息。
你得到:
influxdb.exceptions.InfluxDBClientError: 400: {"error":"database is required"}
Run Code Online (Sandbox Code Playgroud)
然后你应该像这样写你的电话:
client.write(['cpu,atag=test1 idle=100,usertime=10,system=1'],{'db':DBNAME},204,'line')
Run Code Online (Sandbox Code Playgroud)
我改变的事情:
给 ubuntu 用户的注意事项:如果您在撰写本文时使用 ubuntu 包管理器进行安装,您将获得旧版本的 python 客户端,其中 write 函数采用其他参数。因此,如有疑问,请使用 pip 安装。
| 归档时间: |
|
| 查看次数: |
8578 次 |
| 最近记录: |