发布时间:2019-09-17 07:48:50编辑:auto阅读(1973)
python3使用requests模块向influxdb的http API发送接口请求实现数据写入,如下:
1. 创建数据库
[python] view plain copy
import requests
posturl = 'http://192.168.220.128:8086/query'
data = {'q': 'create DATABASE mydb'}
response = requests.post(posturl, data=data)
[python] view plain copy
print(response.status_code)
print(response.headers)
类似于curl命令如下:
[python] view plain copy
curl -POST http://192.168.220.128:8086/query --data-urlencode "q=CREATE DATABASE mydb"
2. 向库中写入数据
[html] view plain copy
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)
[html] view plain copy
print(response.status_code)
print(response.headers)
类似于curl命令如下:
[python] view plain copy
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 '
上一篇: Python_子类调用父类的方法
下一篇: 用ffmpeg 提取MP3
47840
46389
37280
34731
29312
25971
24909
19950
19542
18030
5791°
6411°
5926°
5961°
7063°
5911°
5942°
6437°
6404°
7777°