Kubesense

Metrics API

Programmatically discover and query KubeSense metrics with PromQL using an API key.

KubeSense stores metrics as Prometheus-style time series and exposes them through the Metrics Exploration endpoints under /api/explore. Use them to discover available metrics and to run PromQL queries for charts, dashboards, or current values — authenticating with an API key instead of an interactive login.

These endpoints share the same authentication as the Logs & Traces API.

Base URL

All metrics endpoints are served under the /api/explore prefix on your KubeSense host:

https://<your-kubesense-host>/api/explore
MethodPathDescription
POST/api/explore/metricsList available metric names (with substring search).
POST/api/explore/query-rangeEvaluate a PromQL query over a time range (time-series).
POST/api/explore/queryEvaluate a PromQL query for a single latest value (instant).

Authentication

Every request must include your API key in the X-API-Key header, plus the standard JSON headers:

X-API-Key: <your-api-key>
accept: */*
content-type: application/json

Creating an API key

  1. In the KubeSense UI, go to Settings → API Key Management.
  2. Generate a new key and give it a descriptive label (e.g. inhouse-metrics-exporter).
  3. Copy the key immediately — it is shown only once at creation time. Store it as a secret in your tool.

warning: An API key inherits the role and permissions of the user who created it. Create the key under a user with access to the metrics you want your tool to read.

note: Unlike the logs and traces endpoints, the metrics endpoints take the time range in the JSON body (from_time / to_time, ISO 8601 UTC), not as query params.

List metrics

POST /api/explore/metrics returns the metric names available in the database for a time range. The name field does a substring match on metric names — e.g. "jvm" matches jvm.class.count, jvm.memory.used, and jvm.gc.pause.

curl -s -X POST \
  "https://<your-kubesense-host>/api/explore/metrics" \
  -H "X-API-Key: $KUBESENSE_API_KEY" \
  -H "accept: */*" \
  -H "content-type: application/json" \
  -d '{
    "filters": [],
    "from_time": "2026-02-12T13:16:00.000Z",
    "to_time": "2026-02-12T13:31:00.000Z",
    "limit": 50,
    "name": "jvm"
  }'

Request body fields

FieldTypeRequiredDescription
from_timestring (ISO 8601)YesStart of the time range.
to_timestring (ISO 8601)YesEnd of the time range.
namestringNoSubstring filter on metric names.
limitintegerNoMaximum number of metric names to return.
filtersarrayNoOptional filters to narrow results.

The response is the list of matching metric names plus a total count:

{
  "metrics": [
    "jvm.class.count",
    "jvm.memory.used",
    "jvm.gc.pause"
  ],
  "total": 3
}

Query a time range

POST /api/explore/query-range evaluates a PromQL query at regular intervals across a time range — the shape you want for charts and dashboards. Queries are keyed (A, B, …) inside a queries object so you can evaluate several at once.

curl -s -X POST \
  "https://<your-kubesense-host>/api/explore/query-range" \
  -H "X-API-Key: $KUBESENSE_API_KEY" \
  -H "accept: */*" \
  -H "content-type: application/json" \
  -d '{
    "filters": [],
    "queries": {
      "A": {
        "from_time": "2026-02-12T13:16:00.000Z",
        "to_time": "2026-02-12T13:31:00.000Z",
        "promql": "jvm.class.count{}",
        "step": 30,
        "page": 1,
        "page_size": 50
      }
    }
  }'

Request body fields

FieldTypeRequiredDescription
queriesobjectYesOne or more named query definitions (keyed A, B, …).
filtersarrayNoOptional filters applied to all queries.

Each entry in queries accepts:

FieldTypeRequiredDescription
from_timestring (ISO 8601)YesStart of the time range.
to_timestring (ISO 8601)YesEnd of the time range.
promqlstringYesThe PromQL expression to evaluate.
stepintegerYesInterval between data points, in seconds.
pageintegerNo1-based page number.
page_sizeintegerNoNumber of series per page.

The step parameter

step defines the interval between data points returned across the range:

Step valueInterval
30Every 30 seconds
60Every 1 minute
300Every 5 minutes

Smaller steps return more points; use larger steps over wide ranges to keep responses fast.

Response

The response follows the Prometheus result format — one entry per series, each with its labels and an array of [timestamp, value] points:

{
  "status": "success",
  "data": {
    "result": [
      {
        "metric": { "__name__": "jvm.class.count" },
        "values": [
          [1707743760, "123"],
          [1707743790, "124"],
          [1707743820, "125"]
        ]
      }
    ]
  }
}

Query an instant value

POST /api/explore/query takes the same request body as /query-range but returns the most recent value of the query within the time range — useful for single-stat tiles and current-value lookups.

curl -s -X POST \
  "https://<your-kubesense-host>/api/explore/query" \
  -H "X-API-Key: $KUBESENSE_API_KEY" \
  -H "accept: */*" \
  -H "content-type: application/json" \
  -d '{
    "filters": [],
    "queries": {
      "A": {
        "from_time": "2026-02-12T13:19:46.000Z",
        "to_time": "2026-02-12T13:34:46.000Z",
        "promql": "sum(jvm.class.count{})",
        "step": 30,
        "page": 1,
        "page_size": 50
      }
    }
  }'

Each series returns a single [timestamp, value] pair:

{
  "status": "success",
  "data": {
    "result": [
      {
        "metric": {},
        "value": [1707744086, "245"]
      }
    ]
  }
}

PromQL examples

Use caseQuery
JVM class countjvm.class.count{}
Total JVM classessum(jvm.class.count{})
Memory usagejvm.memory.used{}
HTTP request raterate(http_requests_total[5m])

Replace the promql field with any valid Prometheus expression.

Errors

On failure, the response sets status to error and includes a message:

{
  "status": "error",
  "message": "Invalid API key"
}
StatusMeaning
400Invalid request body (e.g. missing/badly formatted from_time or promql).
401Missing, invalid, or expired API key — or the key's user lacks permission.
500Server error, or a query timeout.

Best practices

  • Call /api/explore/metrics first to discover the exact metric names available.
  • Use /query-range for charts and dashboards (data over time).
  • Use /query for current/latest values (single-stat tiles).
  • Choose an appropriate step for the range to keep responses fast and readable.