cloud-monitoring-chart-generation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud Monitoring Chart Generation Skill (
cloud-monitoring-chart-generation
)

Cloud Monitoring图表生成技能(
cloud-monitoring-chart-generation

Transforms PromQL queries and metric metadata into valid Server-Driven UI (SDUI)
google.monitoring.dashboard.v1.Widget
Protocol Buffer textprotos. These generated textprotos are designed to be ingested by the Cloud Monitoring Dashboards API, gcloud CLI, or declarative dashboard provisioning pipelines.
[!CAUTION] CRITICAL EXECUTION & WORKING DIRECTORY RULES:
  • DO NOT CHANGE WORKING DIRECTORY: Keep your working directory at your workspace root. Do NOT
    cd
    into skill subdirectories.
  • NO DISCOVERY OR SEARCH RULE: The metric descriptor, PromQL query, unit, and resource type are ALWAYS present in the conversation context. NEVER run file or codebase search tools, such as grep, find, directory listings, or codebase queries, to discover metric metadata or inspect repository structures.
  • SCRIPT EXECUTION: Execute the bundled Python scripts directly using python3, for example:
    python3 scripts/assemble_widget_proto.py ...
    .
  • OUTPUT GENERATION: The
    assemble_widget_proto
    script automatically generates deterministic sequential filenames like
    chart.textproto
    and
    chart_2.textproto
    and saves them to the active workspace. The script will handle naming and saving automatically, and will print the generated filename to the console.
将PromQL查询和指标元数据转换为有效的服务器驱动UI(SDUI)
google.monitoring.dashboard.v1.Widget
Protocol Buffer文本原型。这些生成的文本原型专为Cloud Monitoring仪表板API、gcloud CLI或声明式仪表板配置流水线设计,可直接被其读取。
[!CAUTION] 关键执行与工作目录规则:
  • 请勿更改工作目录: 保持工作目录在你的工作区根目录。不要使用
    cd
    命令进入技能子目录。
  • 禁止发现或搜索规则: 指标描述符、PromQL查询、单位和资源类型始终存在于对话上下文当中。绝对不要运行文件或代码库搜索工具,例如grep、find、目录列表或代码库查询,来发现指标元数据或检查仓库结构。
  • 脚本执行: 直接使用python3执行捆绑的Python脚本,例如:
    python3 scripts/assemble_widget_proto.py ...
  • 输出生成:
    assemble_widget_proto
    脚本会自动生成确定性的连续文件名,如
    chart.textproto
    chart_2.textproto
    ,并将其保存到当前工作区。脚本会自动处理命名和保存,并将生成的文件名打印到控制台。

Prerequisites: Environment Setup

前提条件:环境配置

Install the required dependencies in your environment or sandbox:
bash
pip install -r scripts/requirements.txt
在你的环境或沙箱中安装所需依赖:
bash
pip install -r scripts/requirements.txt

3-Stage Pipeline Workflow

三步流水线工作流程

[ Stage 1: compute_labels ]  --->  [ Stage 2: LLM Synthesis ]  --->  [ Stage 3: assemble_widget_proto ]
  Generates candidate labels         Formulates SemanticPlotSpec       Emits validated widget textproto
[ 阶段1: compute_labels ]  --->  [ 阶段2: LLM合成 ]  --->  [ 阶段3: assemble_widget_proto ]
  生成候选标签                生成SemanticPlotSpec          输出经过验证的组件文本原型

Stage 1: Baseline Candidate Synthesis

阶段1:基线候选合成

Run Stage 1 using python3:
bash
python3 scripts/compute_labels.py \
  --metric_display_name "METRIC_DISPLAY_NAME" \
  --resource_type "RESOURCE_TYPE" \
  --metric_unit "UNIT" \
  --promql_query "PROMQL_QUERY"
使用python3运行阶段1:
bash
python3 scripts/compute_labels.py \
  --metric_display_name "METRIC_DISPLAY_NAME" \
  --resource_type "RESOURCE_TYPE" \
  --metric_unit "UNIT" \
  --promql_query "PROMQL_QUERY"

Stage 2: SemanticPlotSpec Prediction (LLM)

阶段2:SemanticPlotSpec预测(LLM)

Review the user prompt, PromQL query structure, and Stage 1 baseline candidates to formulate a 4-key
SemanticPlotSpec
JSON object:
  1. title
    : Polish
    titleCandidate
    to ensure it is concise, human-readable, and under 80 characters.
  2. yAxisLabel
    : Set this to a concise, human-readable quantitative descriptor or metric concept, such as
    "Utilization"
    ,
    "Bytes"
    , or
    "Bytes Rate"
    . Do NOT append unit symbols or suffixes such as
    "(%)"
    ,
    "(/s)"
    , or
    "(By)"
    to the label, because units are rendered automatically via
    unitOverride
    .
  3. plotType
    : Default to
    LINE
    . Use
    STACKED_AREA
    if requested by the user or for distribution queries.
  4. unitOverride
    : Set this to the Unified Code for Units of Measure (UCUM) unit string, derived from the PromQL query by applying the Unit Override Computation Rules below.
查看用户提示、PromQL查询结构和阶段1的基线候选,生成一个包含4个键的
SemanticPlotSpec
JSON对象:
  1. title
    : 优化
    titleCandidate
    ,确保其简洁、易读且长度不超过80个字符。
  2. yAxisLabel
    : 设置为简洁、易读的量化描述符或指标概念,例如
    "利用率"
    "字节"
    "字节速率"
    。不要在标签后附加单位符号或后缀,如
    "(%)"
    "(/s)"
    "(By)"
    ,因为单位会通过
    unitOverride
    自动渲染。
  3. plotType
    : 默认使用
    LINE
    。如果用户要求或用于分布查询,则使用
    STACKED_AREA
  4. unitOverride
    : 设置为统一计量单位代码(UCUM)的单位字符串,根据以下单位覆盖计算规则从PromQL查询推导得出。

Unit Override Computation Rules:

单位覆盖计算规则:

  • Rate Functions (
    rate(...)
    ,
    irate(...)
    )
    : Convert cumulative counters into per-second rates. Append
    /s
    to the raw metric unit. For example, a raw metric unit of
    By
    with
    rate(...)
    results in
    unitOverride: "By/s"
    .
  • Ratios & Percentages (
    100 * ... / ...
    )
    : Ratios of identical metric units multiplied by 100 represent percentages, resulting in
    unitOverride: "%"
    .
  • Normalizations: Normalize
    10^2.%
    to
    "%"
    , per the Unified Code for Units of Measure (UCUM) standard.
  • Preserved Units: For aggregation functions like
    avg_over_time(...)
    or
    sum by (...)
    , retain and output the underlying metric unit without modification. For example, output
    "%"
    ,
    "By"
    , or
    "s"
    unchanged.
  • Legend Template: Do NOT configure the
    legend_template
    field. It is intentionally omitted so that the Cloud Monitoring frontend dynamically renders its multi-column table legend at runtime.
Example
SemanticPlotSpec
:
json
{
  "title": "VM CPU Utilization (us-central1-a)",
  "yAxisLabel": "Utilization",
  "plotType": "LINE",
  "unitOverride": "%"
}
  • 速率函数(
    rate(...)
    irate(...)
    : 将累积计数器转换为每秒速率。在原始指标单位后附加
    /s
    。例如,原始指标单位为
    By
    且使用
    rate(...)
    时,结果为
    unitOverride: "By/s"
  • 比率与百分比(
    100 * ... / ...
    : 相同指标单位的比率乘以100表示百分比,结果为
    unitOverride: "%"
  • 标准化: 根据统一计量单位代码(UCUM)标准,将
    10^2.%
    标准化为
    "%"
  • 保留单位: 对于
    avg_over_time(...)
    sum by (...)
    等聚合函数,保留并输出底层指标单位,不做修改。例如,直接输出
    "%"
    "By"
    "s"
  • 图例模板: 不要配置
    legend_template
    字段。该字段被有意省略,以便Cloud Monitoring前端在运行时动态渲染其多列表格图例。
示例
SemanticPlotSpec
:
json
{
  "title": "VM CPU Utilization (us-central1-a)",
  "yAxisLabel": "Utilization",
  "plotType": "LINE",
  "unitOverride": "%"
}

Stage 3: Protobuf Assembly & Output

阶段3:Protocol Buffer组装与输出

Run Stage 3 using python3 to generate and save the widget textproto:
bash
python3 scripts/assemble_widget_proto.py \
  --promql_query "PROMQL_QUERY" \
  --spec_json 'SEMANTIC_PLOT_SPEC_JSON'
[!IMPORTANT] MANDATORY FILE OUTPUT CONTRACT: The script automatically names and saves output files like
chart.textproto
and
chart_2.textproto
directly in your workspace root without subdirectories.
  • Assigned Filename Feedback: Whenever an output file is saved, the script logs the file path to stderr, for example:
    Wrote widget textproto to: .../chart.textproto
    . Read your command execution logs for the exact filename created so you can target it in Stage 4 validation.
  • Text Chat Output: Enclose the generated SDUI widget textproto inside a
    ```textproto
    code block in your response:
textproto
title: "..."
xy_chart {
  ...
}
使用python3运行阶段3,生成并保存组件文本原型:
bash
python3 scripts/assemble_widget_proto.py \
  --promql_query "PROMQL_QUERY" \
  --spec_json 'SEMANTIC_PLOT_SPEC_JSON'
[!IMPORTANT] 强制文件输出约定: 脚本会自动将输出文件(如
chart.textproto
chart_2.textproto
)命名并保存到你的工作区根目录,无需子目录。
  • 指定文件名反馈: 每当保存输出文件时,脚本会将文件路径记录到stderr,例如:
    Wrote widget textproto to: .../chart.textproto
    。请查看命令执行日志获取创建的确切文件名,以便在阶段4验证中定位该文件。
  • 文本聊天输出: 将生成的SDUI组件文本proto放在
    ```textproto
    代码块中返回:
textproto
title: "..."
xy_chart {
  ...
}

Stage 4: Mandatory Self-Verification & Auto-Retry Loop

阶段4:强制自验证与自动重试循环

[!CAUTION] DO NOT FINISH YOUR TURN UNTIL FILE VERIFICATION PASSES:
  1. Run Validation Check: Execute the validator script against the generated file, such as
    chart.textproto
    or the sequential filename like
    chart_2.textproto
    output from Stage 3:
    bash
    python3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto"
  2. Auto-Retry if Missing or Failed: If
    validate_chart
    reports that the file is missing or invalid, verify your script parameters and immediately re-run Stage 3:
    bash
    python3 scripts/assemble_widget_proto.py \
      --promql_query "PROMQL_QUERY" \
      --spec_json 'SEMANTIC_PLOT_SPEC_JSON'
  3. Validation & Retries: Run
    validate_chart
    to verify the generated textproto. If validation fails due to a schema or syntax error, correct the parameters and retry up to 2 times. If validation still fails after 2 retries, stop retrying, notify the user of the validation error, and present the best-effort textproto.
  4. Execution vs. Validation Errors: Note that schema/syntax validation errors from
    validate_chart.py
    are distinct from OS or environment execution restrictions, such as
    Permission denied
    or
    Command not found
    , which are handled below in Graceful Sandbox Fallback.
[!CAUTION] 验证通过前请勿结束任务:
  1. 运行验证检查: 对阶段3输出的文件(如
    chart.textproto
    或类似
    chart_2.textproto
    的连续文件名)执行验证脚本:
    bash
    python3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto"
  2. 缺失或失败时自动重试: 如果
    validate_chart
    报告文件缺失或无效,请检查脚本参数并立即重新运行阶段3:
    bash
    python3 scripts/assemble_widget_proto.py \
      --promql_query "PROMQL_QUERY" \
      --spec_json 'SEMANTIC_PLOT_SPEC_JSON'
  3. 验证与重试: 运行
    validate_chart
    验证生成的文本proto。如果因架构或语法错误导致验证失败,请修正参数并重试最多2次。如果2次重试后仍失败,请停止重试,通知用户验证错误,并提供尽力生成的文本proto。
  4. 执行错误与验证错误: 请注意,
    validate_chart.py
    返回的架构/语法验证错误与操作系统或环境执行限制(如
    Permission denied
    Command not found
    )不同,后者在优雅沙箱回退部分处理。

Graceful Sandbox Fallback

优雅沙箱回退

If
compute_labels.py
,
assemble_widget_proto.py
, or
validate_chart.py
cannot be executed due to environment or sandbox restrictions, do the following:
  1. Notify the user which script cannot be executed and why.
  2. Synthesize and output the complete widget textproto directly in your response, following all formatting and unit rules.
  3. Provide a "Local Verification" section containing the standalone python3 commands so the user can run and validate the schema locally if desired.
如果由于环境或沙箱限制无法执行
compute_labels.py
assemble_widget_proto.py
validate_chart.py
,请执行以下操作:
  1. 通知用户哪个脚本无法执行以及原因。
  2. 直接在回复中合成并输出完整的组件文本proto,遵循所有格式和单位规则。
  3. 提供**「本地验证」**部分,包含独立的python3命令,以便用户在本地运行并验证架构(如果需要)。

Supporting Links

相关链接