The HTTP API also has two operations: Write and query, this article first introduces you to the Influxdb HTTP API write operation mode.
In the previous article on INFLUXDB study: The basic operation of INFLUXDB learning Influxdb, we mentioned that there are three ways of influxdb operation, one of which is the way of HTTP API.
The HTTP API also has two operations: Write and query, this article first introduces you to the Influxdb HTTP API write operation mode. For more Influxdb detailed tutorials See: INFLUXDB Series Learning Tutorials Catalogue
INFLUXDB Technology Group: 580487672 (click to join)
I. Description
For convenience, this article uses curl primarily to initiate HTTP requests, and the example uses curl as a tool to simulate HTTP requests.
In real-world use, you can write requests to code to emulate HTTP requests through other programming languages.
Ii. influxdb operation of the database via HTTP API
1) Set up a database
Curl-post http://localhost:8086/query--data-urlencode "q=create DATABASE mydb"
After executing this statement, a database named MyDB is created locally.
2) Delete Database
Curl-post http://localhost:8086/query--data-urlencode "Q=drop DATABASE mydb"
In fact, using the HTTP API is to send the corresponding POST request to the InfluxDB interface.
Send the statement to the server via post.
Iii. influxdb Adding data through the HTTP API
Influxdb the use of the HTTP API to add data mainly uses the following format:
Curl-i-xpost ' http://localhost:8086/write?db=mydb '--data-binary ' cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000 '
Description: Db=mydb refers to the use of the MyDB database.
--data-binary is followed by inserting data.
Cpu_load_short is the table name (measurement), and the tag field is host and region, with the values: Server01 and Us-west, respectively.
Field key is a value of 0.64.
The timestamp (timestamp) is specified as 1434055562000000000.
This inserts a piece of data into the Cpu_load_short table of the MyDB database.
Where the DB parameter must specify a database name that already exists in the database, the format of the data body conforms to the INFLUXDB specification format, first the table name, followed by tags, then field, and finally the timestamp. tags, field, and timestamp are separated by a space.
Iv. Influxdb Adding multiple data through the HTTP API
Influxdb adding multiple pieces of data through the HTTP API is similar to adding a single piece of data, such as:
Curl-i-xpost ' http://localhost:8086/write?db=mydb '--data-binary ' Cpu_load_short,host=server02 value=0.67cpu_load_ Short,host=server02,region=us-west value=0.55 1422568543702900257cpu_load_short,direction=in,host=server01, Region=us-west value=2.0 1422568543702900257 '
This statement inserts three data into the table Cpu_load_short of the database MyDB.
The first one specifies the tag as host, the value is Server02, the second specifies the tag as host and region, the values are Server02 and Us-west, the third one specifies the tag direction,host,region, the values are: in, Server01,us-west.
V. HTTP API response for InfluxDB
When using the HTTP API, the INFLUXDB responds mainly to the following:
1) 2xx:204 represents no content,200 on behalf of INFLUXDB can receive the request but does not complete the request. Typically, there is an error message in the body body.
2) 4xx:influxdb cannot parse the request.
3) 5xx: System error occurred.
Well, the HTTP API write for INFLUXDB is first introduced here, and the next one describes how to perform query operations using INFLUXDB's HTTP API.
For more Influxdb detailed tutorials See: INFLUXDB Series Learning Tutorials Catalogue
INFLUXDB Technology Group: 580487672 (click to join)
HTTP API write operations for INFLUXDB learning Influxdb