【问题标题】:Inserting data into Influxdb using Python client with Line protocol使用带有 Line 协议的 Python 客户端将数据插入 Influxdb
【发布时间】:2017-02-28 09:43:51
【问题描述】:

我正在使用 InfluxDb 并且有简单的线路协议线路如下所示:

cpu,atag=test1 idle=100,usertime=10,system=1

我有使用字典的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}])   

只要我通过 write_points 和字典使用 write_points,上面的程序就可以正常工作,但是当我使用 client.write 时,我遇到了错误。

如何通过使用协议值 = 'line' 而不是默认协议 'json' 来使用 client.write 作为提及 here(行号 -255)?

【问题讨论】:

  • 您是否尝试过类似 ("cpu,atag=test1 ...",None,204,"line") ?

标签: python influxdb influxdb-python


【解决方案1】:

您遇到了什么错误?这是非常重要的信息。

你得到:

influxdb.exceptions.InfluxDBClientError: 400: {"error":"database is required"}

那么你应该这样写你的调用:

client.write(['cpu,atag=test1 idle=100,usertime=10,system=1'],{'db':DBNAME},204,'line')

我改变的地方:

  • 线路协议字符串必须在列表中。
  • 不知何故,您需要将数据库名称添加到额外的参数中。我不确定这是临时的“错误”还是预期的功能。
  • 您必须将协议设置为“line”(这也强制您设置预期回报 代码,因为那是协议之前的位置参数)

ubuntu 用户注意事项:如果您在撰写本文时使用 ubuntu 包管理器进行安装,您将获得较旧版本的 python 客户端,其中 write 函数采用其他参数。因此,如有疑问,请使用 pip 安装。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    相关资源
    最近更新 更多