cloud-monitoring-chart-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud Monitoring Chart Generation Skill (cloud-monitoring-chart-generation
)
cloud-monitoring-chart-generationCloud Monitoring图表生成技能(cloud-monitoring-chart-generation
)
cloud-monitoring-chart-generationTransforms PromQL queries and metric metadata into valid Server-Driven UI
(SDUI) Protocol Buffer textprotos.
These generated textprotos are designed to be ingested by the Cloud Monitoring
Dashboards API, gcloud CLI, or declarative dashboard provisioning pipelines.
google.monitoring.dashboard.v1.Widget[!CAUTION] CRITICAL EXECUTION & WORKING DIRECTORY RULES:
- DO NOT CHANGE WORKING DIRECTORY: Keep your working directory at your workspace root. Do NOT
into skill subdirectories.cd- 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
script automatically generates deterministic sequential filenames likeassemble_widget_protoandchart.textprotoand saves them to the active workspace. The script will handle naming and saving automatically, and will print the generated filename to the console.chart_2.textproto
将PromQL查询和指标元数据转换为有效的服务器驱动UI(SDUI) Protocol Buffer文本原型。这些生成的文本原型专为Cloud Monitoring仪表板API、gcloud CLI或声明式仪表板配置流水线设计,可直接被其读取。
google.monitoring.dashboard.v1.Widget[!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.txt3-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 JSON object:
SemanticPlotSpec- : Polish
titleto ensure it is concise, human-readable, and under 80 characters.titleCandidate - : Set this to a concise, human-readable quantitative descriptor or metric concept, such as
yAxisLabel,"Utilization", or"Bytes". Do NOT append unit symbols or suffixes such as"Bytes Rate","(%)", or"(/s)"to the label, because units are rendered automatically via"(By)".unitOverride - : Default to
plotType. UseLINEif requested by the user or for distribution queries.STACKED_AREA - : 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.
unitOverride
查看用户提示、PromQL查询结构和阶段1的基线候选,生成一个包含4个键的 JSON对象:
SemanticPlotSpec- : 优化
title,确保其简洁、易读且长度不超过80个字符。titleCandidate - : 设置为简洁、易读的量化描述符或指标概念,例如
yAxisLabel、"利用率"或"字节"。不要在标签后附加单位符号或后缀,如"字节速率"、"(%)"或"(/s)",因为单位会通过"(By)"自动渲染。unitOverride - : 默认使用
plotType。如果用户要求或用于分布查询,则使用LINE。STACKED_AREA - : 设置为统一计量单位代码(UCUM)的单位字符串,根据以下单位覆盖计算规则从PromQL查询推导得出。
unitOverride
Unit Override Computation Rules:
单位覆盖计算规则:
-
Rate Functions (,
rate(...)): Convert cumulative counters into per-second rates. Appendirate(...)to the raw metric unit. For example, a raw metric unit of/swithByresults inrate(...).unitOverride: "By/s" -
Ratios & Percentages (): Ratios of identical metric units multiplied by 100 represent percentages, resulting in
100 * ... / ....unitOverride: "%" -
Normalizations: Normalizeto
10^2.%, per the Unified Code for Units of Measure (UCUM) standard."%" -
Preserved Units: For aggregation functions likeor
avg_over_time(...), retain and output the underlying metric unit without modification. For example, outputsum by (...),"%", or"By"unchanged."s" -
Legend Template: Do NOT configure thefield. It is intentionally omitted so that the Cloud Monitoring frontend dynamically renders its multi-column table legend at runtime.
legend_template
Example :
SemanticPlotSpecjson
{
"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" -
图例模板: 不要配置字段。该字段被有意省略,以便Cloud Monitoring前端在运行时动态渲染其多列表格图例。
legend_template
示例:
SemanticPlotSpecjson
{
"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 likeandchart.textprotodirectly in your workspace root without subdirectories.chart_2.textproto
- Assigned Filename Feedback: Whenever an output file is saved, the script logs the file path to stderr, for example: . Read your command execution logs for the exact filename created so you can target it in Stage 4 validation.
Wrote widget textproto to: .../chart.textproto - Text Chat Output: Enclose the generated SDUI widget textproto inside a code block in your response:
```textproto
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,例如:。请查看命令执行日志获取创建的确切文件名,以便在阶段4验证中定位该文件。
Wrote widget textproto to: .../chart.textproto - 文本聊天输出: 将生成的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:
- Run Validation Check: Execute the validator script against the generated file, such as
or the sequential filename likechart.textprotooutput from Stage 3:chart_2.textprotobashpython3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto"- Auto-Retry if Missing or Failed: If
reports that the file is missing or invalid, verify your script parameters and immediately re-run Stage 3:validate_chartbashpython3 scripts/assemble_widget_proto.py \ --promql_query "PROMQL_QUERY" \ --spec_json 'SEMANTIC_PLOT_SPEC_JSON'- Validation & Retries: Run
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.validate_chart- Execution vs. Validation Errors: Note that schema/syntax validation errors from
are distinct from OS or environment execution restrictions, such asvalidate_chart.pyorPermission denied, which are handled below in Graceful Sandbox Fallback.Command not found
[!CAUTION] 验证通过前请勿结束任务:
- 运行验证检查: 对阶段3输出的文件(如
或类似chart.textproto的连续文件名)执行验证脚本:chart_2.textprotobashpython3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto"- 缺失或失败时自动重试: 如果
报告文件缺失或无效,请检查脚本参数并立即重新运行阶段3:validate_chartbashpython3 scripts/assemble_widget_proto.py \ --promql_query "PROMQL_QUERY" \ --spec_json 'SEMANTIC_PLOT_SPEC_JSON'- 验证与重试: 运行
验证生成的文本proto。如果因架构或语法错误导致验证失败,请修正参数并重试最多2次。如果2次重试后仍失败,请停止重试,通知用户验证错误,并提供尽力生成的文本proto。validate_chart- 执行错误与验证错误: 请注意,
返回的架构/语法验证错误与操作系统或环境执行限制(如validate_chart.py或Permission denied)不同,后者在优雅沙箱回退部分处理。Command not found
Graceful Sandbox Fallback
优雅沙箱回退
If , , or
cannot be executed due to environment or sandbox restrictions, do the
following:
compute_labels.pyassemble_widget_proto.pyvalidate_chart.py- Notify the user which script cannot be executed and why.
- Synthesize and output the complete widget textproto directly in your response, following all formatting and unit rules.
- Provide a "Local Verification" section containing the standalone python3 commands so the user can run and validate the schema locally if desired.
如果由于环境或沙箱限制无法执行、或,请执行以下操作:
compute_labels.pyassemble_widget_proto.pyvalidate_chart.py- 通知用户哪个脚本无法执行以及原因。
- 直接在回复中合成并输出完整的组件文本proto,遵循所有格式和单位规则。
- 提供**「本地验证」**部分,包含独立的python3命令,以便用户在本地运行并验证架构(如果需要)。