Prometheus 视图管理

更新时间:
复制 MD 格式

当需要跨多个 Prometheus 实例进行统一查询时,可通过 CLI 工具aliyun cms2 创建和管理 Prometheus 视图。Prometheus 视图是一个或多个 Prometheus 实例之上的聚合查询层,支持跨实例统一查询,涵盖创建、查询、更新、删除和列出视图的完整生命周期管理。

说明
  • 视图相关命令位于 prometheus view 命令组下(如 aliyun cms2 prometheus view list)。

  • 视图与实例的 ID 参数统一为 --prometheus-id;视图 ID 也可直接用于 metric promql 命令的 --prometheus-id(同时兼容实例 ID 和视图 ID)。

前提条件

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

参数

类型

说明

--body

string

请求 body,内联 JSON 或 @file.json(必填)

--show-example-body

bool

打印示例请求 body 后退出

--show-schema

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

参数

类型

说明

--prometheus-id

string

Prometheus 视图 ID(必填)

--aliyun-lang

string

语言设置(zh | en)

--resource-group-id

string

资源组 ID

prometheus view update — 更新视图

使用 prometheus view update 命令更新已有 Prometheus 视图,仅修改 body 中包含的字段。

aliyun cms2 prometheus view update --prometheus-id pv-abc123 \
  --body '{"prometheusViewName": "new-name"}'

参数

类型

说明

--prometheus-id

string

Prometheus 视图 ID(必填)

--body

string

请求 body,内联 JSON 或 @file.json(必填)

--show-example-body

bool

打印示例请求 body 后退出

--show-schema

bool

打印请求 body 的 JSON Schema 后退出

prometheus view delete — 删除视图

使用 prometheus view delete 命令删除指定 Prometheus 视图。

说明

删除视图不会影响底层关联的 Prometheus 实例。

aliyun cms2 prometheus view delete --prometheus-id pv-abc123def456

参数

类型

说明

--prometheus-id

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

参数

类型

说明

--filter-region-ids

string

按区域 ID 过滤(逗号分隔)

--max-results

int32

最大返回数量

--next-token

string

分页 token

--prometheus-ids

string

按视图 ID 过滤(逗号分隔)

--prometheus-view-name

string

按视图名称模糊匹配

--resource-group-id

string

资源组 ID

--resource-type

string

资源类型

--tag

string

按标签过滤,JSON 数组格式

--version

string

实例版本(V1 | V2)

--workspace

string

工作空间名称

使用限制

  • create/update 的 body 不做 CLI 侧 Schema 校验,格式错误由 API 返回。

  • --tag 必须是 JSON 数组,字段名小写:[{"key":"k","value":"v"}]。