问题描述
我无法理解如何使用 Python 中的一些 InfluxDB 2 API,使用 InfluxDB 2 的 influxdb-client-python 库
例如,我想获取桶中的测量值列表。
官方文档(不是 Python)建议:
使用 schema.measurements() 函数列出存储桶中的测量值。
import "influxdata/influxdb/schema"
schema.measurements(bucket: "example-bucket")
解决方法
我已经搜索了图书馆的代码,看看我是否能找到可以做到这一点的东西。我可能错了,但似乎 as of right now 没有此功能的接口。
但是,可以通过执行以下操作来做您想做的事情:
from influxdb_client import InfluxDBClient
address = "myaddress"
token = "mytoken"
org = "myorg"
client = InfluxDBClient(url=address,token=token,org=org)
qapi = client.query_api()
q = 'import "influxdata/influxdb/schema"\n\nschema.measurements(bucket: "example-bucket")'
tables = qapi.query(q)
for table in tables:
print(table)
for record in table.records:
print(record.values)
您必须用您自己的变量替换此代码示例中定义的任何变量。另外,请确保查询中的存储桶名称与您要查询的存储桶匹配。
最后,您使用的令牌必须具有足够的权限才能完成任务。