Query PromQL data
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.
The
metric promqlcommand group includes commands for PromQL, such asaliyun cms2 metric promql query.The
--prometheus-idparameter is compatible with both Prometheus instance IDs and Prometheus view IDs. TheGetPrometheusInstanceoperation parses the query endpoint for both ID types.
Prerequisites
The CLI tool is installed and configured.
A Prometheus instance is available with data ingested.
Shared parameters and authentication methods
The following parameters apply to all metric promql subcommands:
Parameter | Type | Default value | Description |
| string | The ID of the Prometheus instance to query. This parameter is required. | |
| string |
| The network type. Valid values: |
| string | The language setting ( | |
| string | The ID of the resource group. |
PromQL queries use the following authentication order:
The query first uses the instance's
authTokenfor Bearer Token authentication.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 |
| string | PromQL expression. Required. |
| string | Evaluation timestamp in RFC 3339 format (for example, |
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 300sParameter | Type | Description |
| string | PromQL expression. Required. |
| string | Start timestamp in RFC 3339 or Unix seconds. Required. |
| string | End timestamp in RFC 3339 or Unix seconds. Required. |
| string | Query resolution step in Prometheus duration format (for example, |
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 |
| string | Start timestamp. Optional. |
| string | End timestamp. Optional. |
| stringArray | Series selector. Optional. Can be specified multiple times. |
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 |
| Positional argument | Label name. Required. Specify exactly one. |
| string | Start timestamp. Optional. |
| string | End timestamp. Optional. |
| 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 1784179082Parameter | Type | Description |
| stringArray | Series selector. Required. Can be specified multiple times. Specify at least one. |
| string | Start timestamp. Required. |
| string | End timestamp. Required. |
Subcommand parameter summary
Subcommand | Specific parameters | Description |
|
| Instant query. |
|
| Range query. All four are required. |
|
| All optional. |
|
|
|
|
| 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.
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 |
| The same request always produces the same error. | Do not retry. Modify the query conditions. |
| Temporary cause such as throttling. | Wait at least 300 ms, then retry once. |
| 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, andseriessubcommands explicitly reject the--query,--time, and--stepparameters.The
--matchparameter 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.retryPolicyautomatic retry mechanism.