Add API to query influxdb info

This commit is contained in:
DingZQ
2025-02-15 15:15:36 +08:00
parent 13cdae6362
commit 1a23667b1b
2 changed files with 44 additions and 0 deletions

View File

@@ -1328,6 +1328,42 @@ def query_curve_by_ID_property_daterange(ID: str, type: str, property: str, star
return results
def query_buckets(client: InfluxDBClient=client) -> list[str]:
# 获取 Buckets API 实例
buckets_api = client.buckets_api()
# 查询所有 Buckets
buckets = buckets_api.find_buckets().buckets
print("All Buckets:")
buckets_list = []
for bucket in buckets:
buckets.append(bucket.name)
return buckets_list
def query_tags(bucket: str, client: InfluxDBClient=client) -> list[str]:
query_api = client.query_api()
# 定义 Flux 查询
query = f'''
from(bucket: "your-bucket")
|> range(start: -1y) # 时间范围(可根据需要调整)
|> filter(fn: (r) => r._measurement == "{bucket}")
|> tagKeys() # 直接获取所有 Tag 键名
'''
# 执行查询
result = query_api.query(query)
# 提取 Tag 列表
tag_keys = []
for table in result:
for record in table.records:
tag_keys.append(record.get_value())
tag_keys
# 示例调用
if __name__ == "__main__":
url = influxdb_info.url