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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay