Install and get started with CLI tools

Updated at:

The Cloud Monitor 2.0 CLI (aliyun cms2) is a plugin for the Alibaba Cloud CLI. It is built on OpenAPI version 2024-03-30 and lets you perform full lifecycle management for features such as Application Real-Time Monitoring Service, Managed Service for Prometheus, Real User Monitoring (RUM), alerting rules, and Synthetic Monitoring.

Installation and updates

For more information, see Install, update, and uninstall Alibaba Cloud CLI.

Check the version

aliyun cms2 --version

The output is formatted as follows:

version: vX.Y.Z
git commit: <short-hash>
build date: <ISO8601>

Configure credentials

For more information, see Configure and manage credentials.

Output formats

The aliyun cms2 CLI supports the following output formats:

Text format (-o text, default)

  • list command: The output to stdout is a compact CSV format. The first line is a metadata comment: # <entity> returned=N total=T truncated=<true|false>. This line is followed by the table header and data rows. The columns vary by command. For more information, see the --help output for each subcommand.

  • get command: The output to stdout is a single-line compact JSON object: {"success":true,"data":{...}}

JSON format (-o json)

  • Output on success (stdout):

    {
      "success": true,
      "data": {...}
    }
  • Output on failure (stdout):

    {
      "success": false,
      "error": {...}
    }

Both success and failed envelopes are written to stdout. This allows for direct parsing by cmd | jq. The stderr stream is used only for auxiliary information, such as alerts and progress updates. If a command fails, the process returns a non-zero exit code.

Prometheus passthrough output (exception)

The metric promql labels, label-values, series, and query/query-range commands output raw Prometheus HTTP API JSON ({"status": "success", "data": ...}). The output is not wrapped in the CLI's success envelope.

Common error codes

Error code

Description

Recommended action

InvalidArgument

Missing or invalid required parameter

Check the command parameters.

NotFound

Unknown resource ID

Rerun the corresponding list command.

Forbidden

Insufficient credential permissions

Grant the AliyunCloudMonitorFullAccess permission.

Command overview

Commands use a nested 'resource + action' structure, such as aliyun cms2 integration policy create. The main top-level commands are:

Command

Description

integration

Integration Center: policies, add-ons, add-on releases, storage, dashboards, and collection targets.

workspace

Workspace management.

prometheus

Prometheus instances, views, and recording rules.

grafana

Grafana workspace.

apm

Application Monitoring (APM).

rum

Browser Monitoring (RUM).

synthetics

Synthetic Monitoring (Synthetics).

resource-watermark

Resource usage.

alert

Alerting rules, templates, and history.

notification-channel

Notification channels.

event-hub

Event center.

metric

Metric query, including the Prometheus Query Language (PromQL) subcommand (metric promql ...).

entity

Entity query.

meta

Metadata query.

trace

Tracing analysis (Trace).

aliyun-service

Query the activation status of Alibaba Cloud services.

commands

List all commands.

Note

You can view the complete command tree by running aliyun cms2 --help. For help with a specific command level, run <command> --help.

Quick start example

The following is a typical workflow for connecting a Container Service for Kubernetes (ACK) cluster to Cloud Monitor using the CLI:

# 1. Configure credentials
aliyun configure set \
  --access-key-id YOUR_AK --access-key-secret YOUR_SK \
  --region cn-hangzhou

# 2. View available integration add-ons
aliyun cms2 integration addon list
aliyun cms2 integration addon --addon-name cloud-acs-ack

# 3. Create an integration policy
aliyun cms2 integration policy create --body '{
  "policyType": "CS",
  "policyName": "my-ack-policy",
  "workspace": "default-cms-12345-cn-hangzhou",
  "entityGroup": {
    "clusterEntityType": "acs.ack.cluster",
    "clusterId": "c1234567890abcdef"
  }
}'

# 4. Deploy the add-on
aliyun cms2 integration addon-release create --policy-id ip-xxx --body '{
  "addonName": "cloud-acs-ack",
  "version": "*",
  "envType": "CS",
  "workspace": "default-cms-12345-cn-hangzhou",
  "values": "{\"clusterId\":\"c1234567890abcdef\"}"
}'

# 5. Verify data reporting
aliyun cms2 metric promql query --prometheus-id pi-xxx --query 'up'