Z', 'value': 224}, {'time': '2018-05-23T11:55:55.414792607Z', 'value': 415}, {'time': '2018-05-23T11:55:55.422871017Z', 'value': 644}]})
删除表
删除数据库
说明:
class influxdb.InfluxDBClient(host=u'localhost', port=8086, username=u'root', password=u'root', database=None, ssl=False, verify_ssl=False, timeout=None, retries=3, use_udp=False, udp_port=4444, proxies=None)
参数
host (str) – 用于连接的InfluxDB主机名称,默认‘localhost’
port (int) – 用于连接的Influxport端口,默认8086
username (str) – 用于连接的用户名,默认‘root’
password (str) – 用户密码,默认‘root’
database (str) – 需要连接的数据库,默认None
ssl (bool) – 使用https连接,默认False
verify_ssl (bool) – 验证https请求的SSL证书,默认False
timeout (int) – 连接超时时间(单位:秒),默认None,
retries (int) – 终止前尝试次数(number of retries your client will try before aborting, defaults to 3. 0 indicates try until success)
use_udp (bool) – 使用UDP连接到InfluxDB默认False
udp_port (int) – 使用UDP端口连接,默认4444
proxies (dict) – 为请求使用http(s)代理,默认 {}
query(query, params=None, epoch=None, expected_response_code=200, database=None, raise_errors=True, chunked=False, chunk_size=0)
参数:
query (str) – 真正执行查询的字符串
params (dict) – 查询请求的额外参数,默认{}
epoch (str) – response timestamps to be in epoch format either ‘h’, ‘m’, ‘s’, ‘ms’, ‘u’, or ‘ns’,defaults to None which is RFC3339 UTC format with nanosecond precision
expected_response_code (int) – 期望的响应状态码,默认 200
database (str) – 要查询的数据库,默认数据库
raise_errors (bool) – 查询返回错误时,是否抛出异常,默认
chunked (bool) – Enable to use chunked responses from InfluxDB. With chunked enabled, one ResultSet is returned per chunk containing all results within that chunk
chunk_size (int) – Size of each chunk to tell InfluxDB to use.
返回数据查询结果集
write_points(points, time_precision=None, database=None, retention_policy=None, tags=None, batch_size=None, protocol=u'json')
参数
points 由字典项组成的list,每个字典成员代表了一个
time_precision (str) – Either ‘s’, ‘m’, ‘ms’ or ‘u’, defaults to None
database (str) – points需要写入的数据库,默认为当前数据库
tags (dict) – 同每个point关联的键值对,key和value都要是字符串.
retention_policy (str) – the retention policy for the points. Defaults to None
batch_size (int) – value to write the points in batches instead of all at one time. Useful for when doing data dumps from one database to another or when doing a massive write operation, defaults to None
protocol (str) – Protocol for writing data. Either ‘line’ or ‘json’.
如果操作成功,返回True
就query,write_points操作来说,如果操作执行未调用switch_database函数,切换到目标数据库,可以在调用query,write_points函数时,可以指定要操作的数据库,如下
client.query('show measurements;', database='mytestdb')
client.write_points(json_body, database='mytestdb')
points参数值,可以不指定 time,这样采用influxdb自动生成的时间
json_body = [
{
"measurement": "table1",
"tags": {
"stuid": "stuid1"
},
# "time": "2018-05-16T21:58:00Z",
&nbs