Query PromQL data

Updated at:

For daily O&M and troubleshooting, you can use the CLI aliyun cms2 to query a Prometheus instance. You can execute various types of PromQL queries, such as instant and range queries, along with metadata queries for labels and series.

Note
  • The metric promql command group includes commands for PromQL, such as aliyun cms2 metric promql query.

  • The --prometheus-id parameter is compatible with both Prometheus instance IDs and Prometheus view IDs. The GetPrometheusInstance operation parses the query endpoint for both ID types.

Prerequisites

Shared parameters and authentication methods

The following parameters apply to all metric promql subcommands:

Parameter

Type

Default value

Description

--prometheus-id

string

The ID of the Prometheus instance to query. This parameter is required.

--network

string

internet

The network type. Valid values: internet or vpc.

--aliyun-lang

string

The language setting (zh | en).

--resource-group-id

string

The ID of the resource group.

PromQL queries use the following authentication order:

  1. The query first uses the instance's authToken for Bearer Token authentication.

  2. If no token is provided, the query falls back to Basic Auth using an AccessKey pair. In the Simple Log Service (SLS) MetricStore compatible pattern, the user is the AccessKey ID and the password is the AccessKey secret or AccessKeySecret$SecurityToken.

metric promql query — Instant query

Run a PromQL instant query to evaluate an expression at a single point in time. The following examples show common usage:

# Basic query
aliyun cms2 metric promql query --prometheus-id pi-abc123 --query 'up'

# Query at a specific timestamp (RFC 3339 format)
aliyun cms2 metric promql query --prometheus-id pi-abc123 \
  --query 'node_memory_MemAvailable_bytes' \
  --time 2026-07-15T05:05:23Z

# Query at a specific timestamp (Unix seconds)
aliyun cms2 metric promql query --prometheus-id pi-abc123 \
  --query 'node_cpu_seconds_total' --time 1784091923

# Query over VPC network
aliyun cms2 metric promql query --prometheus-id pi-abc123 \
  --network vpc --query 'up'

Parameter

Type

Description

--query

string

PromQL expression. Required.

--time

string

Evaluation timestamp in RFC 3339 format (for example, 2026-07-15T05:05:23Z) or Unix seconds (for example, 1784091923). Default value: the current time.

Note

The query subcommand does not support the --start, --end, or --step parameters. Use query-range for range queries.

metric promql query-range — Range query

Run a PromQL range query over a time window. The --start, --end, and --step parameters are all required.

# Query CPU usage over the past 24 hours
aliyun cms2 metric promql query-range --prometheus-id pi-abc123 \
  --query 'rate(container_cpu_usage_seconds_total[5m])' \
  --start '2026-07-15T05:18:01Z' \
  --end '2026-07-16T05:18:01Z' \
  --step 60s

# Range query using Unix timestamps
aliyun cms2 metric promql query-range --prometheus-id pi-abc123 \
  --query 'node_memory_MemAvailable_bytes' \
  --start 1784092681 --end 1784179081 --step 300s

Parameter

Type

Description

--query

string

PromQL expression. Required.

--start

string

Start timestamp in RFC 3339 or Unix seconds. Required.

--end

string

End timestamp in RFC 3339 or Unix seconds. Required.

--step

string

Query resolution step in Prometheus duration format (for example, 15s, 60s, 5m, or 1h). Required.

Note

The query-range subcommand does not support the --time parameter. Using it causes an error.

metric promql labels — List label names

Query all label names in a Prometheus instance. This corresponds to the Prometheus HTTP API endpoint /api/v1/labels.

# List all label names
aliyun cms2 metric promql labels --prometheus-id pi-abc123

# Specify a time range
aliyun cms2 metric promql labels --prometheus-id pi-abc123 \
  --start '2026-07-16T04:05:23Z' --end '2026-07-16T05:05:23Z'

# Filter by series selector
aliyun cms2 metric promql labels --prometheus-id pi-abc123 --match 'up'

Parameter

Type

Description

--start

string

Start timestamp. Optional.

--end

string

End timestamp. Optional.

--match

stringArray

Series selector. Optional. Can be specified multiple times.

Note

The labels command outputs the raw Prometheus API JSON ({"status":"success","data":...}) without the CLI success envelope wrapping. You can pipe the output directly to jq for processing.

metric promql label-values — List label values

Query all values for a specified label name. This corresponds to the Prometheus HTTP API endpoint /api/v1/label/<name>/values.

# List all metric names
aliyun cms2 metric promql label-values __name__ --prometheus-id pi-abc123

# List values of a label, filtered by selector
aliyun cms2 metric promql label-values job --prometheus-id pi-abc123 \
  --match 'up{namespace="monitoring"}'

# Pipe to jq
aliyun cms2 metric promql label-values __name__ --prometheus-id pi-abc123 | jq '.data[]'

Parameter

Type

Description

<label_name>

Positional argument

Label name. Required. Specify exactly one.

--start

string

Start timestamp. Optional.

--end

string

End timestamp. Optional.

--match

stringArray

Series selector. Optional. Can be specified multiple times.

metric promql series — Find matching series

Find series that match specified selectors. This corresponds to the Prometheus HTTP API endpoint /api/v1/series.

# Basic series match
aliyun cms2 metric promql series --prometheus-id pi-abc123 \
  --match 'up' --start '2026-07-16T04:18:02Z' --end '2026-07-16T05:18:02Z'

# Multiple matchers
aliyun cms2 metric promql series --prometheus-id pi-abc123 \
  --match 'node_cpu_seconds_total{mode="idle"}' \
  --match 'node_memory_MemTotal_bytes' \
  --start 1784175482 --end 1784179082

Parameter

Type

Description

--match

stringArray

Series selector. Required. Can be specified multiple times. Specify at least one.

--start

string

Start timestamp. Required.

--end

string

End timestamp. Required.

Subcommand parameter summary

Subcommand

Specific parameters

Description

query

--query, --time

Instant query. --query is required.

query-range

--query, --start, --end, --step

Range query. All four are required.

labels

--start, --end, --match

All optional.

label-values

<label_name> (positional), --start, --end, --match

<label_name> is required.

series

--match, --start, --end

All required.

MetricStore response

The Alibaba Cloud Prometheus data plane uses Simple Log Service (SLS) MetricStore instances. The Prometheus HTTP API extends the standard response with an slsStatus field.

Important

An HTTP 200 response that contains slsStatus indicates that the returned data may be incomplete. A success: true at the CLI level means only that the HTTP call succeeded. It does not guarantee data integrity.

The slsStatus.retryPolicy field has the following values. The CLI does not implement automatic retries. You must implement retries externally.

retryPolicy

Meaning

Recommendation

None

The same request always produces the same error.

Do not retry. Modify the query conditions.

Once

Temporary cause such as throttling.

Wait at least 300 ms, then retry once.

Continuous

Server-side issue that may recover.

Use backoff retry (300 ms, doubling up to a maximum of 10 s).

Limits

  • Only GET requests are used. Very long PromQL expressions may hit URL length limits.

  • The labels, label-values, and series subcommands explicitly reject the --query, --time, and --step parameters.

  • The --match parameter uses the stringArray type and does not split comma-separated values. PromQL selectors that contain commas can be used safely.

  • The CLI is a single-execution tool and does not implement the slsStatus.retryPolicy automatic retry mechanism.