DEV Community

Francesco Tisiot
Francesco Tisiot

Posted on • Originally published at ftisiot.net

1

How to query remote InfluxDB via cURL

Terminal showing the cURL code to query InfluxDB

Sometimes 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 hostname
  • PORT: Database port
  • PROTOCOL: Protocol to connect to the database HTTPS, HTTP
  • USERNAME: Username to connect to the database
  • PASSWORD: Password to connect to the database
  • DB_NAME: Database name
  • QUERY_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>"
Enter fullscreen mode Exit fullscreen mode

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\""
Enter fullscreen mode Exit fullscreen mode

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
                        ],
                        ]
                }
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay