The HTTP API is the primary means for querying data in InfluxDB.
To perform a query send a GET
request to the /query
endpoint, set the URL parameter db
as the target database, and set the URL parameter q
as your query.
1 | curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west'" |
InfluxDB returns JSON. The results of your query appear in the 'result'
array. If an error occurs, InfluxDB sets an 'error'
key with an explanation of the error.
1 | { |
Note: Appending
pretty=true
to the URL enables pretty-printed JSON output. While this is useful for debugging or when queryting directly with tools likecurl
, it is not recommended for production use as it consumes unnecessary network bandwidth.
Multiple queries
Send multiple queries to InfluxDB in a single API call. Simply delimit each query using a semicolon
1 | curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west';SELECT count(\"value\") FROM \"cpu_load_short\" WHERE \"region\"='us-west'" |