from influxdb import InfluxDBClient
host = '1.2.3.4'
port = '8086'
user = 'influxdb'
password = 'influxdb_pwd'
dbname = 'aka-demo'
# 连接influxdb库
client = InfluxDBClient(host, port, user, password, dbname)
result = client.get_list_measurements()
# 显示所有的measurement
for item in result:
measurement = item['name']
# 来点色彩
print("\033[1;40m =============%s==============\033[0m" % measurement)
print("tag", end=":")
tag_result = client.query("SHOW TAG KEYS FROM " + measurement)
for tag_item in tag_result:
for tag in tag_item:
print(tag['tagKey'], end=",")
print()
print("field", end=":")
field_result = client.query("SHOW FIELD KEYS FROM " + measurement)
for field_item in field_result:
for field in field_item:
print(field['fieldKey'], end=",")
print()
sql_result = client.query("select * from %s order by time limit 5" % measurement)
# get_points()这个方法,要看influxdb库的官方文件
for points in sql_result.get_points():
print(points)
模糊查询
# 时区及设置时间范围:
select * from mymeasurement where time >='2018-07-16T10:00:00Z' tz('Asia/Shanghai')
# 实现查询以给定字段开始的数据
select fieldName from measurementName where fieldName=~/^给定字段/;
# 实现查询以给定字段结束的数据
select fieldName from measurementName where fieldName=~/给定字段$/
# 实现查询包含给定字段数据
select fieldName from measurementName where fieldName=~/给定字段/
# 模糊查询例子:
SELECT * FROM "measurementName" where time>='2021-07-02T06:34:10.029308697Z' and fieldName=~/21$/ tz('Asia/Shanghai');
其他操作可看:
https://blog.csdn.net/xiligey1/article/details/104530893/
网友评论