使用python脚本向influxdb写

发布时间: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 '




关键字