当需要跨多个 Prometheus 实例进行统一查询时,可通过 CLI 工具aliyun cms2 创建和管理 Prometheus 视图。Prometheus 视图是一个或多个 Prometheus 实例之上的聚合查询层,支持跨实例统一查询,涵盖创建、查询、更新、删除和列出视图的完整生命周期管理。
视图相关命令位于
prometheus view命令组下(如aliyun cms2 prometheus view list)。视图与实例的 ID 参数统一为
--prometheus-id;视图 ID 也可直接用于metric promql命令的--prometheus-id(同时兼容实例 ID 和视图 ID)。
前提条件
已完成CLI工具安装与配置。
已创建至少一个 Prometheus 实例。
prometheus view create — 创建视图
使用 prometheus view create 命令创建新的 Prometheus 视图。body 内容按原样透传给 CMS API,成功后响应返回 prometheusViewId(生成的视图 ID)和 requestId。
aliyun cms2 prometheus view create --body '{
"prometheusViewName": "global-view",
"workspace": "default-cms-12345-cn-hangzhou"
}'
# 从 JSON 文件创建
aliyun cms2 prometheus view create --body @./prometheus-view-create.json参数 | 类型 | 说明 |
| string | 请求 body,内联 JSON 或 |
| bool | 打印示例请求 body 后退出 |
| bool | 打印请求 body 的 JSON Schema 后退出 |
prometheus view get — 查询视图
使用 prometheus view get 命令根据视图 ID 获取 Prometheus 视图的完整详情,包括视图名称、工作空间、关联实例和状态。
aliyun cms2 prometheus view get --prometheus-id pv-abc123def456
# 设置语言和资源组
aliyun cms2 prometheus view get --prometheus-id pv-xxx \
--aliyun-lang zh --resource-group-id rg-xxx
# JSON 输出
aliyun cms2 prometheus view get --prometheus-id pv-abc123 -o json参数 | 类型 | 说明 |
| string | Prometheus 视图 ID(必填) |
| string | 语言设置( |
| string | 资源组 ID |
prometheus view update — 更新视图
使用 prometheus view update 命令更新已有 Prometheus 视图,仅修改 body 中包含的字段。
aliyun cms2 prometheus view update --prometheus-id pv-abc123 \
--body '{"prometheusViewName": "new-name"}'参数 | 类型 | 说明 |
| string | Prometheus 视图 ID(必填) |
| string | 请求 body,内联 JSON 或 |
| bool | 打印示例请求 body 后退出 |
| bool | 打印请求 body 的 JSON Schema 后退出 |
prometheus view delete — 删除视图
使用 prometheus view delete 命令删除指定 Prometheus 视图。
删除视图不会影响底层关联的 Prometheus 实例。
aliyun cms2 prometheus view delete --prometheus-id pv-abc123def456参数 | 类型 | 说明 |
| string | Prometheus 视图 ID(必填) |
prometheus view list — 列出视图
使用 prometheus view list 命令列出 Prometheus 视图,支持多种过滤条件和分页。list 为单页请求,不自动翻页,通过 --next-token 参数进行手动翻页。
# 列出工作空间下所有视图
aliyun cms2 prometheus view list --workspace default-cms-12345-cn-hangzhou
# 按名称模糊匹配
aliyun cms2 prometheus view list --prometheus-view-name global
# 按区域和版本过滤
aliyun cms2 prometheus view list --filter-region-ids cn-hangzhou --version V2
# 按视图 ID 列表过滤
aliyun cms2 prometheus view list --prometheus-ids pv-001,pv-002
# 按标签过滤
aliyun cms2 prometheus view list --tag '[{"key":"team","value":"sre"}]'
# 分页查询
aliyun cms2 prometheus view list --workspace my-ws --max-results 10 --next-token "eyJ..."
# 文本(CSV)输出
aliyun cms2 prometheus view list --workspace my-ws -o text参数 | 类型 | 说明 |
| string | 按区域 ID 过滤(逗号分隔) |
| int32 | 最大返回数量 |
| string | 分页 token |
| string | 按视图 ID 过滤(逗号分隔) |
| string | 按视图名称模糊匹配 |
| string | 资源组 ID |
| string | 资源类型 |
| string | 按标签过滤,JSON 数组格式 |
| string | 实例版本( |
| string | 工作空间名称 |
使用限制
create/update的 body 不做 CLI 侧 Schema 校验,格式错误由 API 返回。--tag必须是 JSON 数组,字段名小写:[{"key":"k","value":"v"}]。