Skip to main content

Querying Last9 using HTTP API

How to query metrics from Last9 using HTTP API

This step-by-step guide explains how to query Last9 using HTTP API.

Last9 Read URL

Create a Last9 cluster by following Getting Started. Each Last9 Cluster comes with a Read URL which needs to be used when querying metrics data from Last9.

Last9 Read Data Settings

You can grab the Read URL by going to the Last9 Cluster → Settings → Read Data → Bring Your Own Visualization.

info

Last9 Read URL mandates authenticated access. Create a Read Token for your cluster and use it as password. Use the cluster id as username.

Keep the following information handy after creating the Last9 cluster:

  • $levitate_read_url - Last9's Read endpoint
  • $levitate_username - Cluster ID
  • $levitate_password - Read token created for the cluster

Authentication

Generate the authorization header for authenticated access to Last9 metrics API as follows.

USERNAME="$levitate_ cluster_username"
PASSWORD="$levitate_cluster_password"
BASIC_AUTH_HEADER=$(echo -n "$USERNAME:$PASSWORD" | base64)
AUTH_HEADER="Authorization: Basic $BASIC_AUTH_HEADER"
info

Last9 is Prometheus compatible TSDB. You can query metrics stored in Last9 using Prometheus HTTP API.

Instant Query

The simplest way to query Last9 is to use $levitate_read_url along with $AUTH_HEADER, which allows you to execute an instant query.

curl -XPOST "$levitate_read_url/api/v1/query?query=<promQL>" -H "$AUTH_HEADER"

Example:

Query the current CPU usage:

curl -XPOST "$levitate_read_url/api/v1/query?query=node_cpu_seconds_total{}" -H "$AUTH_HEADER"

Range Query

Use the query_range endpoint to retrieve data over a time range. You need to specify the start time, end time, and step duration.

curl -XPOST '$levitate_read_url/api/v1/query_range?query=<promQL>&start=<start-time>&end=<end-time>&step=<step-duration>' -H "$AUTH_HEADER"

Example:

Query CPU usage over the last hour with a 1-minute step:

curl -XPOST '$levitate_read_url/api/v1/query_range?query=node_cpu_seconds_total&start=$(date -d "1 hour ago" +%s)&end=$(date +%s)&step=60' -H "$AUTH_HEADER"
tip

For more details, refer to the Prometheus HTTP API documentation.

Troubleshooting

Please get in touch with us on Discord or Email if you have any questions.