Python操作InfluxDB笔记

部署运行你感兴趣的模型镜像

详细API

要连接influxdb数据库,需创建一个influxdb client,目前支持两种客户端:

  • InfluxDBClient
  • DataFrameClient

InfluxDBClient

可以使用以下几种连接方式来创建InfluxDBClient对象

from influxdb import InfluxDBClient

# using Http
client = InfluxDBClient(database='dbname')
client = InfluxDBClient(host='127.0.0.1', port=8086, database='dbname')
client = InfluxDBClient(host='127.0.0.1', port=8086, username='root', password='root', database='dbname')

# using UDP
client = InfluxDBClient(host='127.0.0.1', database='dbname', use_udp=True, udp_port=4444)

InfluxDBClient类的参数说明

参数说明
hostInfluxDB主机, 默认为 ‘localhost’
port (int)端口号,默认8086
password (str)––密码,默认root
username (str)用户名,默认root
pool_size (int)urllib3 连接池大小,默认10
–ssl (bool)–是否使用https连接InfluxDB,默认False
database (str)要连接的数据库名,默认None
verify_ssl (bool)是否对https请求采用ssl认证,默认False
timeout (int)–请求创建连接到客户端的timeout秒数,默认None–
retries (int)连接客户端重试次数,默认3
use_udp (bool)是否使用udp连接InfluxDB, 默认False
–udp_port (int)–UDP port, 默认4444
proxies (dict)HTTP(S) 代理,默认为空dict
path (str)服务器上InfluxDB的连接路径, 默认为’’

cert (str) – 客户端证书信息的路径,用于相互TLS身份验证。您可以指定本地证书,以用作包含私钥和证书的单个文件,也可以用作两个文件路径的元组,默认为None

InfluxDB类的方法

  • 修改数据库的现有保存策略

alter_retention_policy(name, database=None, duration=None,
replication=None, default=None, shard_duration=None)

  • 关闭http会话
> close()
  • 为数据库创建一个连续的查询
> create_continuous_query(name, select, database=None, resample_opts=None)
> 
  • 在InfluxDB中创建一个新数据库
create_database(dbname)
  • 为数据库创建保留策略
create_retention_policy(name, duration, replication, database=None, default=False, shard_duration=u'0s')
  • 在InfluxDB中创建一个新用户
create_user(username, password, admin=False)
  • 从数据库中删除Series
delete_series(database=None, measurement=None, tags=None)
  • 删除现有的数据库连续查询
drop_continuous_query(name, database=None)
  • 从InfluxDB中删除数据库
drop_database(dbname)
  • 从InfluxDB中删除一个measurement
drop_measurement(measurement)
  • 删除数据库的现有保留策略
drop_retention_policy(name, database=None)
  • 从InfluxDB中删除用户
drop_user(username)
  • 类方法:从给定的数据源名称生成一个InfluxDBClient实例 classmethodfrom_dsn(dsn, **kwargs)
    举例:
cli = InfluxDBClient.from_dsn('influxdb://username:password@\localhost:8086/databasename', timeout=5)
  • 获取InfluxDB中连续查询的列表

python get_list_continuous_queries()

  • 获取InfluxDB中的数据库列表

get_list_database()

  • 获取InfluxDB中的measurements列表

get_list_measurements()

  • 获取授予给定用户的所有特权的列表

get_list_privileges(username)

  • 获取数据库的保留策略列表

get_list_retention_policies(database=None)

  • 获取InfluxDB中所有用户的列表

get_list_users()

  • 向用户授予管理员权限

grant_admin_privileges(username)

  • 向用户授予数据库权限

grant_privilege(privilege, database, username)

  • 检查与InfluxDB的连接

ping()

  • 查询
query(query, params=None, bind_params=None, epoch=None, expected_response_code=200, database=None, raise_errors=True, chunked=False, chunk_size=0, method=u'GET')
  • 向InfluxDB API发出HTTP请求
request(url, method=u'GET', params=None, data=None, expected_response_code=200, headers=None)
  • 撤消用户的管理员权限

revoke_admin_privileges(username)

  • 撤消用户对数据库的权限

revoke_privilege(privilege, database, username)

  • 发送UDP数据包

send_packet(packet, protocol=u’json’, time_precision=None)

  • 更改现有用户的密码

set_user_password(username, password)

  • 更改客户端的数据库

switch_database(database)

  • 更改客户端的用户名

switch_user(username, password)

  • 写入数据库

write(data, params=None, expected_response_code=204, protocol=u’json’)

  • 写入多个时间序列名称
write_points(points, time_precision=None, 
database=None, retention_policy=None, tags=None, 
batch_size=None, protocol=u'json', consistency=None)

您可能感兴趣的与本文相关的镜像

FLUX.1-dev

FLUX.1-dev

图片生成
FLUX

FLUX.1-dev 是一个由 Black Forest Labs 创立的开源 AI 图像生成模型版本,它以其高质量和类似照片的真实感而闻名,并且比其他模型更有效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值