您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python操作InfluxDB

bubuko 2022/1/25 19:10:44 python 字数 7364 阅读 866 来源 http://www.bubuko.com/infolist-5-1.html

influxdb包:influxdb 通过Python使用InfluxDBClient类操作数据库,操作如下: from influxdb import InfluxDBClient client = InfluxDBClient('localhost', 8086, 'username', 'pa ...

influxdb包:influxdb

通过Python使用InfluxDBClient类操作数据库,操作如下:

from influxdb import InfluxDBClient

client = InfluxDBClient(localhost, 8086, username, password, dbname)

# 显示已存在的数据库
print(client.get_list_database())
# 创建数据库
client.create_database(py_db1)
print(client.get_list_database())
# 删除数据库
client.drop_database(py_db1)
print(client.get_list_database())

写入:

# 待写入数据库的点组成的列表
points = [
    {
        measurement: table1,
        tags: {
            host: server01,
            region: us-west
        },
        time: 2021-04-16T12:00:00Z,
        fields: {
            value: 0.64
        }
    }
]

# 将这些点写入指定database
client.write_points(points, database=py_db1)

# 查询刚刚写入的点
result = client.query(select value from table1;, database=py_db1)

print(result)
[{name: _internal}, {name: db0415}, {name: mydb}]
ResultSet({(table1, None): [{time: 2021-04-16T12:00:00Z, value: 0.64}]})

 

Python操作InfluxDB

原文:https://www.cnblogs.com/wangzhilong/p/14675393.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶