Back to Nightingale

Prometheus / VictoriaMetrics Metric Queries

aiagent/skill/embedded/builtin/query-datasource/datasources/prometheus.md

9.1.13.5 KB
Original Source

Prometheus / VictoriaMetrics Metric Queries

  • plugin_type: prometheus
  • Query language: PromQL
  • Use case: Metric/time-series queries

Discover Available Metrics

Retrieve the list of all metric names:

GET /api/n9e/proxy/<datasource_id>/api/v1/label/__name__/values
Authorization: Bearer <token>

Get All Label Names

GET /api/n9e/proxy/<datasource_id>/api/v1/labels
Authorization: Bearer <token>

Get Label Values

GET /api/n9e/proxy/<datasource_id>/api/v1/label/<label_name>/values
Authorization: Bearer <token>

Query Time-Series Metadata

GET /api/n9e/proxy/<datasource_id>/api/v1/series?match[]=<metric_selector>&start=<unix_ts>&end=<unix_ts>
Authorization: Bearer <token>

Instant Query

Query the metric value at a specific point in time:

POST /api/n9e/query-instant-batch
Authorization: Bearer <token>
Content-Type: application/json
json
{
  "datasource_id": 1,
  "queries": [
    {
      "time": 1712003600,
      "query": "cpu_usage_active{ident='web-01'}"
    }
  ]
}
FieldTypeRequiredDescription
datasource_idint64YesDatasource ID
queries[].timeint64YesQuery time, Unix timestamp (seconds)
queries[].querystringYesPromQL expression

Response format:

json
{
  "dat": [
    {
      "resultType": "vector",
      "result": [
        {
          "metric": {"__name__": "cpu_usage_active", "ident": "web-01"},
          "value": [1712003600, "85.6"]
        }
      ]
    }
  ]
}

Range Query

Query the metric trend over a period of time:

POST /api/n9e/query-range-batch
Authorization: Bearer <token>
Content-Type: application/json
json
{
  "datasource_id": 1,
  "queries": [
    {
      "start": 1712000000,
      "end": 1712003600,
      "step": 60,
      "query": "cpu_usage_active{ident='web-01'}"
    }
  ]
}
FieldTypeRequiredDescription
datasource_idint64YesDatasource ID
queries[].startint64YesStart time, Unix timestamp (seconds)
queries[].endint64YesEnd time, Unix timestamp (seconds)
queries[].stepint64YesSampling step (seconds)
queries[].querystringYesPromQL expression

Recommended step values:

Time Rangestep
1 hour15s
6 hours60s
24 hours300s
7 days1800s

Response format:

json
{
  "dat": [
    {
      "resultType": "matrix",
      "result": [
        {
          "metric": {"__name__": "cpu_usage_active", "ident": "web-01"},
          "values": [
            [1712000000, "82.3"],
            [1712000060, "83.1"],
            [1712000120, "85.6"]
          ]
        }
      ]
    }
  ]
}

Query Directly Through the Proxy

You can also call the native Prometheus API directly through the proxy:

GET /api/n9e/proxy/<datasource_id>/api/v1/query?query=up&time=<unix_ts>
GET /api/n9e/proxy/<datasource_id>/api/v1/query_range?query=up&start=<ts>&end=<ts>&step=60
Authorization: Bearer <token>

Common PromQL Examples

RequirementPromQL
CPU usagecpu_usage_active
Memory usagemem_used_percent
Disk usagedisk_used_percent{path="/"}
Inbound network throughput raterate(net_bytes_recv[5m])
1-minute loadsystem_load1
HTTP request raterate(http_requests_total[5m])
All metrics of a given instance{ident="web-01"}
Aggregation: average per instanceavg by (ident)(cpu_usage_active)
Top 10 CPUtopk(10, cpu_usage_active)