How to query remote InfluxDB via cURL
- One minute read - 164 wordsSometimes you want to query a remote InfluxDB server to understand the data in it. This can be done via cURL as explained in the InfluxDB docs
Parameters
HOSTNAME
: Database hostnamePORT
: Database portPROTOCOL
: Protocol to connect to the databaseHTTPS
,HTTP
USERNAME
: Username to connect to the databasePASSWORD
: Password to connect to the databaseDB_NAME
: Database nameQUERY_STR
: Query string to be exectuted. The query string needs to be properly escaped, e.g.SELECT \"ts_ms\" FROM \"test_measurement\"
cURL Query Code
Execute the following by replacing the parameters above
curl -G 'https://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/query?pretty=true' \
--data-urlencode "db=<DB_NAME>" \
--data-urlencode "q=<QUERY_STR>"
As example to get the SELECT \"ts_ms\" FROM \"test_measurement\"
you can run:
curl -G 'https://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/query?pretty=true' \
--data-urlencode "db=<DB_NAME>" \
--data-urlencode "q=SELECT \"ts_ms\" FROM \"test_measurement\""
Results:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "TEST",
"columns": [
"time",
"ts_ms"
],
"values": [
[
"2022-11-07T08:50:20.772317361Z",
1667809412536
],
[
"2022-11-07T08:50:20.789690226Z",
1667809412547
],
[
"2022-11-07T08:50:20.79052872Z",
1667809412548
],
[
"2022-11-07T08:51:53.165095297Z",
1667811112824
],
]
}
]
}
]
}