关于 cx-service-catalog
cx-service-catalog 是用于通过 v2 Service Catalog API 查询服务、数据库、Kubernetes Pod 等实体及其指标的 CLI 技能,面向应用与服务监控场景。它提供从发现实体类型和字段到聚合查询及单实体下钻的只读流程。
主要功能
- 01发现可用实体类型与实体
- 02查看实体类型字段和标签架构
- 03按时间范围查询聚合指标
- 04按实体查询并下钻分析
- 05支持表格与时间序列结果
- 06支持 JSON、TOON 和多配置文件
适用场景
- 01检查服务或数据库的延迟与错误率
- 02分析 Kubernetes Pod 资源使用情况
- 03按标签筛选或分组实体指标
- 04查看单个服务的历史延迟趋势
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ coralogix/ cx-cli --skill cx-service-catalog安装后在 Claude Code 中输入/cx-service-catalog确认已加载。
详细介绍
服务目录技能
使用此技能,通过 v2 Service Catalog API 发现和查询 服务目录实体——服务、 数据库、操作、数据库操作、JVM、JVM GC、Kubernetes Pod 和事务——以及它们的列式指标(延迟、错误率、运行状况、资源 使用情况等)。
CLI 命令
| 命令 | 用途 | 关键标志 |
|---|---|---|
cx service-catalog entity-types | 列出此账户有数据的实体类型 | - |
cx service-catalog schema <entity-type> | 查看一种实体类型的列/标签架构 | - |
cx service-catalog entities <entity-type> | 列出一种类型的已知实体(例如,服务名称) | - |
cx service-catalog data <entity-type> | 汇总一种类型所有实体的列数据 | --start、--end、--column(必填,可重复);--group-by、--filter、--aggregation、--limit、--sort-column、--sort-order |
cx service-catalog entity-data <entity-type> <entity-id> | 查看一个命名实体的列数据(下钻) | --start、--end、--column(必填,可重复);--group-by、--filter、--aggregation |
- 所有命令均为只读,并支持使用
-o json/-o toon输出结构化数据。 - 实体类型接受简写形式:
service、database、operation、database-operation、jvm、jvm-gc、k8s-pod、transaction(不区分大小写, 可使用连字符或下划线)。完整 proto 名称(ENTITY_TYPE_K8S_POD)也可用。 未知值会在客户端被拒绝,不会发起请求。 --start/--end接受now、now-1h这类相对表达式或 RFC3339 时间戳。--column为必填,且可重复;请先运行cx service-catalog schema <entity-type>查询有效列 ID;API 会拒绝未知 ID。--filter label=value1,value2可重复,但只能针对不同标签 (过滤条件之间使用 AND);同一标签的多个值请用逗号组合,而不要重复该标志——客户端会拒绝重复的标签。--aggregation可设为table(与--limit/--sort-column/--sort-order结合时的默认行为)或timeseries。--limit、--sort-column和--sort-order仅适用于table——后端会静默忽略它们在timeseries中的设置,因此 CLI 会提前拒绝这种组合,而不会发送一个标志会被悄然丢弃的请求。entity-data会为你对实体 ID 进行百分号编码——请传入entities返回的原始值 (例如checkout/api);如果值中包含/,请用引号括起来。
检查工作流
分为四个步骤,且每一步都提供了下一步所需的输入:
entity-types 提供有效的 <entity-type> 值,schema 提供有效的
--column ID,entities 提供下钻所需的 entity-id。
-
发现有哪些实体类型——切勿猜测,不同账户的类型可能不同:
cx service-catalog entity-types -o json -
检查架构,找到一种实体类型的有效列 ID 和 可用于过滤/分组的标签:
cx service-catalog schema service -o json -
列出该类型的已知实体(例如,服务名称):
cx service-catalog entities service -o json -
查询数据——汇总所有实体的数据,或限定到某一个实体。下方的列 ID、过滤/分组标签和实体 ID 都是占位符——请始终替换为
schema/entities返回的、对应实体类型的值, 因为这些值因账户和实体类型而异:cx service-catalog data <entity-type> --start now-1h --end now \ --column <column-id> --column <column-id> -o json cx service-catalog entity-data <entity-type> <entity-id> --start now-1h --end now \ --column <column-id> -o json
示例
以下命令使用 service 和 k8s-pod 作为示例,但每个
<column-id>、<filterable-label>、<groupable-label> 和 <entity-id>
都必须来自该实体类型自身的 schema/entities 输出——切勿假设一种实体类型的列或标签也存在于另一种实体类型中。
按指标列出过去一小时内排名前 5 的实体
cx service-catalog schema service -o json # discover column ids first
cx service-catalog data service --start now-1h --end now \
--column <column-id> --aggregation table \
--sort-column <column-id> --sort-order desc --limit 5 -o json
过滤到一个标签值
cx service-catalog schema service -o json # discover filterable_labels first
cx service-catalog data service --start now-1h --end now \
--column <column-id> --column <column-id> \
--filter <filterable-label>=<value> -o json
按标签分组
cx service-catalog schema service -o json # discover groupable_labels first
cx service-catalog data service --start now-1h --end now \
--column <column-id> --group-by <groupable-label> -o json
Kubernetes Pod 资源饱和度
cx service-catalog schema k8s-pod -o json # discover column ids first
cx service-catalog data k8s-pod --start now-1h --end now \
--column <column-id> --column <column-id> --column <column-id> -o json
查看一个实体随时间变化的延迟
cx service-catalog entities service -o json # discover entity ids first
cx service-catalog entity-data service <entity-id> --start now-24h --end now \
--column <column-id> --aggregation timeseries -o json
仅显示行
# Table responses live under .rows; timeseries under .series
cx service-catalog data service --start now-1h --end now \
--column <column-id> -o json | jq '.rows'
核心原则
- 先发现,再查询 ——
entity-types和schema的成本很低,可在对data/entity-data发起猜测性调用前,先回答“这里有哪些有效内容”。 --column的值因实体类型而异 —— 对service有效的列,可能不存在于k8s-pod中;切换实体类型时,务必重新检查schema。- 格式错误的响应属于错误,而不是静默的空结果 —— 某列既不是值也不是错误(或两者兼有)时,会明确报错,而不是返回不完整或空行。因此,非零退出码意味着需要排查,而不是“没有数据”。
- 列级错误不代表命令失败 —— 单个列可能在其他内容成功的行中返回
{"error": "..."}(例如,只有该列的查询超时);在认定整个请求失败之前,请检查各列。 table和timeseries是互斥的结果形态 ——table响应是扁平行,适合使用-o json | jq '.rows';timeseries响应会按序列嵌套数据点,最好直接使用原始 JSON,而不要强行转换为表格。- 过滤时使用
-o json和jq;在 Agent 场景中,使用-o toon获取更节省令牌的输出。 - 多配置文件扇出适用于每个子命令 —— 重复使用
-p <profile>,即可跨账户比较相同实体类型或数据;指定多个配置文件时,行和序列会附带profile标记。
相关技能
cx-infra—— 基础设施资源健康状况(主机、容器)与 Service Catalog 实体健康状况是不同概念;主机/实例级监控请使用cx-infra,应用/服务级 APM 实体请使用此技能。cx-telemetry-querying—— 此技能的命令显示服务或 Pod 名称后,可进一步查询原始遥测数据:使用cx logs "filter $l.subsystemname == '<service>'",或使用cx search-fields "<name>" -s value查找相关日志/跨度字段。将延迟或错误峰值与底层日志/跨度相关联。cx-alerts——cx alerts list --name "<service-name>"可查找与此技能发现的服务匹配的警报定义。cx-dashboards——cx dashboards search "<service-name> ..."可查找围绕此处发现的服务构建的仪表板。