Python script writes data to Influxdb

Source: Internet
Author: User
Tags curl python script influxdb

Python3 uses the requests module to send an interface request to the INFLUXDB HTTP API to write data, as follows:

1. Create a database


[python] view plain copy

  1. Import Requests

  2. posturl =  ' http://192.168.220.128:8086/query '   

  3. data = {' q ': ' Create DATABASE mydb '}

  4. Response = Requests.post (PostURL, Data=data)

[python] view plain copy

  1. Print (Response.status_code)

  2. Print (response.headers)

The following are similar to the Curl command:


[python] view plain copy

  1. curl-post/HTTP192.168.220.128:8086/query--data-urlencode"Q=create DATABASE mydb"  

2. Writing data to the library


[HTML] view plain copy

  1. Import requests

  2. posturl ' http://192.168.220.128:8086/write?db=mydb '   

  3. Data = "Cpu_load_short,host=server01,region=us-west value=0.69"   

  4. Response = Requests. Post (PostURL,Data=Data)  

[HTML] view plain copy

    1. print (Response.status_code)   

    2. print (response.headers)   

The following are similar to the Curl command:


[python] view plain copy

  1. 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 script writes data to Influxdb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.