Python第三方模块influxdb使用手册

pip安装influxdb模块

pip install influxdb

API

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

  • InfluxDBClient
  • DataFrameClient

InfluxDBClient

可以使用这几种连接方式来连接数据库,创建InfluxDBClient对象

from influxdb import InfluxDBClient

# using Http
client = InfluxDBClient(database='test')
client = InfluxDBClient(host='192.168.0.200', port=8086, database='test')
client = InfluxDBClient(host='192.168.0.200', port=8086, username='monitor', password='123321', database='test')

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

InfluxDBClient类的参数说明

参数释义
hostinfluxdb主机地址,默认localhost
port(int)端口号,默认8086
username(str)用户名,默认root
password(str)密码,默认root
pool_size(int)urlib3连接池大小,默认10
database(str)数据库名,默认none
ssl(bool)是否使用https连接,默认false
timeout(int)请求创建连接到客户端的超时时间,默认none
retries(int)连接客户端重试次数,默认3
use_udp(bool)是否使用udp连接数据库,默认false
udp_port(int)udp端口数,默认4444

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中连续查询的列表
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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Energet!c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值