Refine
This commit is contained in:
@@ -1355,28 +1355,6 @@ def query_measurements(bucket: str, client: InfluxDBClient=client) -> list[str]:
|
||||
return measurements
|
||||
|
||||
|
||||
def query_tags(bucket: str, measurement: str, client: InfluxDBClient=client) -> list[str]:
|
||||
query_api = client.query_api()
|
||||
|
||||
# 定义 Flux 查询
|
||||
query = f'''
|
||||
from(bucket: "{bucket}")
|
||||
|> range(start: -1y) # 时间范围(可根据需要调整)
|
||||
|> filter(fn: (r) => r._measurement == "{measurement}")
|
||||
|> 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())
|
||||
#
|
||||
return tag_keys
|
||||
|
||||
# 示例调用
|
||||
if __name__ == "__main__":
|
||||
url = influxdb_info.url
|
||||
|
||||
3
main.py
3
main.py
@@ -2138,9 +2138,6 @@ async def fastapi_query_influxdb_buckets():
|
||||
async def fastapi_query_influxdb_bucket_measurements(bucket: str):
|
||||
return influxdb_api.query_measurements(bucket=bucket)
|
||||
|
||||
@app.get("/queryinfluxdbbuckettags/")
|
||||
async def fastapi_query_influxdb_bucket_tags(bucket: str, measurement: str):
|
||||
return influxdb_api.query_tags(bucket=bucket, measurement=measurement)
|
||||
|
||||
|
||||
# DingZQ, 2024-12-31, generate openapi.json
|
||||
|
||||
Reference in New Issue
Block a user