Cloud Monitoring Chart Generation

Cloud Monitoring Chart Generation

Turns PromQL or ListTimeSeries queries into valid Cloud Monitoring dashboard widget textprotos with titles, axis labels and plot types, validated by bundled scripts.

Skill files11 files

references/

scripts/

SKILL.md250 lines
1
---
2
name: cloud-monitoring-chart-generation
3
metadata:
4
version: "1.0.2"
5
category: CloudObservabilityAndMonitoring
6
description: >-
7
Generates Cloud Monitoring Server-Driven UI (SDUI) Widget and XyChart Protocol
8
Buffer textprotos on Google Cloud from resolved PromQL or ListTimeSeries
9
queries.
10
Use when:
11
- Generating valid google.monitoring.dashboard.v1.Widget textprotos,
12
containing PrometheusQuery or TimeSeriesFilter datasets, for use with the Cloud Monitoring
13
Dashboards API, gcloud CLI, or declarative dashboard definitions.
14
- Synthesizing Server-Driven UI (SDUI) widget titles, axis labels, and
15
plot types for Prometheus or ListTimeSeries queries.
16
Don't use for:
17
- Metric discovery or PromQL query generation. For those tasks, use the
18
cloud-monitoring-metric-selection or cloud-monitoring-promql-query skills.
19
---
20
21
# Cloud Monitoring Chart Generation Skill (`cloud-monitoring-chart-generation`)
22
23
Transforms PromQL or ListTimeSeries JSON request payloads and metric metadata
24
into valid Server-Driven UI (SDUI) `google.monitoring.dashboard.v1.Widget`
25
Protocol Buffer textprotos. These generated textprotos are designed to be
26
ingested by the Cloud Monitoring Dashboards API, gcloud CLI, or declarative
27
dashboard provisioning pipelines.
28
29
> [!IMPORTANT] **Preferred API & Mutually Exclusive Queries**:
30
> - **API Preference**: Always prefer generating `ListTimeSeries` (`time_series_filter`) configurations for widgets over PromQL, unless the user explicitly requested PromQL or the metric math strictly requires it.
31
> - **Mutually Exclusive**: A widget dataset `time_series_query` must contain **EITHER** a `time_series_filter` OR a `prometheus_query`. You must never populate both fields in the same dataset simultaneously.
32
> - **Strict Passthrough**: You MUST copy the provided PromQL query or ListTimeSeries JSON exact filter string character-for-character. DO NOT invent, rewrite, or modify the queries under any circumstances.
33
34
> [!CAUTION] **CRITICAL EXECUTION & WORKING DIRECTORY RULES**:
35
>
36
> - **DO NOT CHANGE WORKING DIRECTORY**: Keep your working directory at your
37
> workspace root. Do NOT `cd` into skill subdirectories.
38
> - **NO DISCOVERY OR SEARCH RULE**: The metric descriptor, PromQL query,
39
> ListTimeSeries JSON payload, unit, and resource type are ALWAYS present in
40
> the conversation context. **NEVER** run file or codebase search tools,
41
> like grep, find, directory listings, or codebase queries, to discover
42
> metric metadata or inspect repository structures.
43
> - **SCRIPT EXECUTION**: Execute the bundled Python scripts directly using
44
> python3.
45
> - **OUTPUT GENERATION**: The `assemble_widget_proto` script automatically
46
> generates a unique UUID-based filename to prevent parallel execution
47
> collisions. It will print the generated filename to standard error
48
> strongly prefixed with "Wrote widget textproto to:". You MUST parse this
49
> exact prefix from the logs to extract the generated path and use it for
50
> validation in Stage 4.
51
52
## Attribution
53
54
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
55
MUST read [Usage Attribution](references/attribution.md). For commands executed
56
directly in the terminal (never in generated scripts, Terraform, or user code),
57
prefix `gcloud` with
58
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-chart-generation)"`
59
and append `agent-skills/1.0 (skill:cloud-monitoring-chart-generation)` to `User-Agent` headers.
60
61
## Prerequisites: Environment Setup
62
63
Install the required dependencies in your environment or sandbox:
64
65
```bash
66
pip install -r scripts/requirements.txt
67
```
68
69
## Follow the workflow pipeline
70
71
```
72
[ Stage 1: compute_labels ] ---> [ Stage 2: LLM Synthesis ] ---> [ Stage 3: assemble_widget_proto ]
73
Generates candidate labels Formulates SemanticPlotSpec Emits validated widget textproto
74
```
75
76
### Stage 1: Baseline Candidate Synthesis
77
78
Run Stage 1 using python3:
79
80
```bash
81
# For PromQL:
82
python3 scripts/compute_labels.py \
83
--metric_display_name "METRIC_DISPLAY_NAME" \
84
--resource_type "RESOURCE_TYPE" \
85
--metric_unit "UNIT" \
86
--promql_query 'PROMQL_QUERY'
87
88
# For ListTimeSeries:
89
python3 scripts/compute_labels.py \
90
--metric_display_name "METRIC_DISPLAY_NAME" \
91
--resource_type "RESOURCE_TYPE" \
92
--metric_unit "UNIT" \
93
--filter_string 'metric.type="m"...' \
94
--per_series_aligner "ALIGN_RATE" \
95
--cross_series_reducer "REDUCE_SUM"
96
```
97
98
### Stage 2: SemanticPlotSpec Prediction (LLM)
99
100
Review the user prompt, PromQL or LTS query structure, and Stage 1 baseline
101
candidates to formulate a 4-key `SemanticPlotSpec` JSON object:
102
103
1. **`title`**: Polish `titleCandidate` to ensure it is concise, human-readable,
104
and under 80 characters.
105
2. **`yAxisLabel`**: Set this to a concise, human-readable quantitative
106
descriptor or metric concept, like `"Utilization"`, `"Bytes"`, or `"Bytes
107
Rate"`. Do NOT append unit symbols or suffixes like `"(%)"`, `"(/s)"`, or
108
`"(By)"` to the label, because units are rendered automatically via
109
`unitOverride`.
110
3. **`plotType`**: Default to `LINE`. Use `STACKED_AREA` if requested by the
111
user or for distribution queries.
112
4. **`unitOverride`**: Set this to the Unified Code for Units of Measure (UCUM)
113
unit string, derived by applying the corresponding rules below:
114
115
#### List Time Series (LTS) Unit Strategy:
116
117
- **Trust the Candidate**: For List Time Series flows, set this directly to
118
the `unitOverrideCandidate` produced by Stage 1. Stage 1 mathematically
119
processes `ALIGN_RATE`, for example producing `By/s`, forces `%` for
120
`ALIGN_PERCENT_CHANGE`, and correctly outputs native normalizations
121
unconditionally.
122
123
#### PromQL Unit Strategy (LLM Manual Override):
124
125
Because PromQL expressions can geometrically compose, for example
126
`histogram_quantile(..., rate(...))`, rely on your own semantic reasoning to
127
govern the final unit:
128
129
- **Rate Functions (`rate(...)`, `irate(...)`)**: Convert cumulative counters
130
into per-second rates. Append `/s` to the raw metric unit. For example, a
131
raw metric unit of `By` with `rate(...)` results in `unitOverride: "By/s"`.
132
- **Exception**: If `rate()` is evaluated inside a `histogram_quantile()`,
133
the output is the raw bucket unit like `"s"`, not a rate.
134
- **Ratios & Percentages (`100 * (A / B)`)**: Ratios of identical metric units
135
typically represent percentages, resulting in `unitOverride: "%"`.
136
- **Normalizations**: Normalize `10^2.%` to `"%"`.
137
- **Preserved Units**: For simple aggregation functions like
138
`avg_over_time(...)` or `sum by (...)`, retain and output the underlying
139
metric unit without modification.
140
141
- **Legend Template**: Do NOT configure the `legend_template` field. It is
142
intentionally omitted so that the Cloud Monitoring frontend dynamically
143
renders its multi-column table legend at runtime.
144
145
Example `SemanticPlotSpec`:
146
147
```json
148
{
149
"title": "VM CPU Utilization us-central1-a",
150
"yAxisLabel": "Utilization",
151
"plotType": "LINE",
152
"unitOverride": "%"
153
}
154
```
155
156
### Stage 3: Protobuf Assembly & Output
157
158
Run Stage 3 using python3 to generate and save the widget textproto. Use
159
`--promql_query` for PromQL, or `--lts_request_json` for ListTimeSeries:
160
161
```bash
162
# For PromQL:
163
python3 scripts/assemble_widget_proto.py \
164
--promql_query 'PROMQL_QUERY' \
165
--spec_json 'SEMANTIC_PLOT_SPEC_JSON'
166
167
# For ListTimeSeries:
168
python3 scripts/assemble_widget_proto.py \
169
--lts_request_json '{"filter": "...", "aggregation": {...}}' \
170
--spec_json 'SEMANTIC_PLOT_SPEC_JSON'
171
```
172
173
> [!IMPORTANT] **MANDATORY FILE OUTPUT CONTRACT**: Do not attempt to guess or
174
> enforce the output filename. The script will automatically generate a
175
> guaranteed-unique filename and print it to standard error. Search stderr for
176
> the explicit prefix "Wrote widget textproto to:" to deterministically capture
177
> this filename, and then target it in Stage 4 validation.
178
179
- **Assigned Filename Feedback**: Whenever an output file is saved, the script
180
logs the file path to stderr. Read your command execution logs for the exact
181
filename created so you can target it in Stage 4 validation.
182
- **Text Chat Output**: Enclose the generated SDUI widget textproto inside
183
a ```` ```textproto```` code block in your response:
184
185
```textproto
186
title: "..."
187
xy_chart {
188
...
189
}
190
```
191
192
### Verify and auto-retry
193
194
> [!CAUTION] **DO NOT FINISH YOUR TURN UNTIL FILE VERIFICATION PASSES**: 1.
195
> **Validate Artifact**: Execute the validator script against the generated file
196
> output from Stage 3:
197
>
198
> ```bash
199
> # For PromQL charts:
200
> python3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto" \
201
> --expected_promql_substring "SOME_IDENTIFYING_SUBSTRING_FROM_QUERY" \
202
> --expected_unit_override "UNIT_OVERRIDE_CANDIDATE"
203
>
204
> # For ListTimeSeries (LTS) charts:
205
> python3 scripts/validate_chart.py --input_file "GENERATED_FILE.textproto" \
206
> --expected_lts_filter_substring "SOME_IDENTIFYING_SUBSTRING_FROM_FILTER" \
207
> --expected_unit_override "UNIT_OVERRIDE_CANDIDATE"
208
>
209
> # ALWAYS provide an identifying substring and the Stage 1 unit override candidate to verify you didn't mutate the data.
210
211
> # CRITICAL: If you generated multiple charts for multiple metrics, you MUST run this validation script independently for EACH file generated to ensure every chart is correct!
212
> ```
213
>
214
> 2. **Auto-Retry if Missing or Failed**: If `validate_chart` reports that the
215
> file is missing or invalid, verify your script parameters and immediately
216
> re-run Stage 3:
217
>
218
> ```bash
219
> python3 scripts/assemble_widget_proto.py \
220
> --promql_query 'PROMQL_QUERY' \
221
> --spec_json 'SEMANTIC_PLOT_SPEC_JSON'
222
> # Or use --lts_request_json if applicable
223
> ```
224
> 3. **Validation & Retries**: Run `validate_chart` to verify the generated
225
> textproto. If validation fails due to a schema or syntax error, correct
226
> the parameters and retry up to 2 times. If validation still fails after 2
227
> retries, stop retrying, notify the user of the validation error, and
228
> present the best-effort textproto.
229
> 4. **Execution vs. Validation Errors**: Note that schema/syntax validation
230
> errors from `validate_chart.py` are distinct from OS or environment
231
> execution restrictions, which are handled below in **Graceful Sandbox
232
> Fallback**.
233
234
#### Perform graceful sandbox fallback
235
236
If `compute_labels.py`, `assemble_widget_proto.py`, or `validate_chart.py`
237
cannot be executed due to environment or sandbox restrictions, do the
238
following:
239
240
1. Notify the user which script cannot be executed and why.
241
2. **Synthesize and output the complete widget textproto directly in your
242
response**, following all formatting and unit rules.
243
3. Provide a **"Local Verification"** section containing the standalone python3
244
commands so the user can run and validate the schema locally if desired.
245
246
## Supporting Links
247
248
- [Dashboards API](https://docs.cloud.google.com/monitoring/dashboards/api-dashboard)
249
- [Prometheus Docs](https://prometheus.io/docs/prometheus/latest/querying/)
250

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…