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 '
共同学习,写下你的评论
评论加载中...
作者其他优质文章