发布时间:2019-08-07 14:07:05编辑:auto阅读(1738)
python3使用requests模块向influxdb的http API发送接口请求实现数据写入,如下:
1. 创建数据库
import requests
posturl = 'http://192.168.220.128:8086/query'
data = {'q': 'create DATABASE mydb'}
response = requests.post(posturl, data=data)
print(response.status_code)
print(response.headers)
类似于curl命令如下:
curl -POST http://192.168.220.128:8086/query --data-urlencode "q=CREATE DATABASE mydb"
2. 向库中写入数据
import requests
posturl = 'http://192.168.220.128:8086/write?db=mydb'
data="cpu_load_short,host=server01,region=us-west value=0.69"
response = requests.post(posturl, data=data)
print(response.status_code)
print(response.headers)
类似于curl命令如下:
curl -i -XPOST 'http://192.168.220.128:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 '
上一篇: Python3实现常用数据标准化方法
下一篇: python3学习笔记
47494
45794
36793
34324
28968
25598
24443
19611
19111
17632
5466°
6048°
5570°
5638°
6573°
5376°
5378°
5884°
5855°
7170°