cloud-monitoring-promql-query
它能做什么
这个技能编写用于读取 Google Cloud 指标的 PromQL 查询。它适用于比起标准 Cloud Monitoring 过滤格式,更喜欢 PromQL 的人。
适用场景
- ✓当你想要一个 PromQL 查询来绘制 Cloud Monitoring 指标图表或设置警报的时候。
- ✓当你需要用 PromQL 编写 Google Cloud 资源的聚合的时候。
- ✓当你想把指标转换为正确的 PromQL 结构的时候。
技能链接
https://github.com/google/skills/blob/main/skills/cloud/cloud-monitoring-promql-query/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请写一个 PromQL 查询,显示我的 Cloud Run 服务每分钟的错误率。”
每周 5 个新技能,1 分钟读完。
工作原理
它会先检查你的项目 ID,然后把指标和资源详情映射到 Google Cloud 所要求的 PromQL 结构。它会返回可直接使用的查询。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Cloud Monitoring PromQL Generator
Use this skill to generate a valid PromQL query from any Cloud Monitoring metric type. This guide applies to all Cloud Monitoring metric types by mapping Cloud Monitoring metric and resource descriptors to PromQL structures.
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-promql-query)"
and append agent-skills/1.0 (skill:cloud-monitoring-promql-query) to User-Agent headers.
Workflow
Resolve Project ID (CRITICAL & BLOCKING)
Before performing any other actions (such as searching code, reading references, or running validation), you MUST verify whether the Google Cloud Project ID is available:
- Check Prompt/Payload: Look for the Project ID in the user's prompt or input.
- Check Environment: If the Project ID is not present in the prompt, you
MUST run
gcloud config get-value projectto attempt to resolve it from the environment. - Ask for Clarification (BLOCKING): If the Project ID is not in the prompt
AND the
gcloudcommand fails, returns an empty string, or is unavailable, you MUST immediately stop. Do NOT generate a PromQL query, do not run the validation script, and do not use placeholders (likeYOUR_PROJECT_ID). You must refuse to proceed and ask the user to provide the Project ID.
Inspect Metric and Resource Descriptors
- Use Provided Descriptors First: If the user's prompt already includes
metric descriptor details (such as
metric.type,metricKind,valueType, ormonitoredResourceTypes) or specific resource filter values, use those values directly instead of calling the Cloud Monitoring API. - Discover Missing Descriptors: If exact metric descriptors
(
metric.type,metricKind,valueType) are missing or underspecified, resolve the target metric type's descriptor using one of these paths:- Vague Query: If the prompt is vague (for example,
"VM CPU usage"), use thecloud-monitoring-metric-selectionskill first to identify the specific metric type. - Known Metric Type: If you already have the specific metric type name
(for example,
compute.googleapis.com/instance/cpu/utilization) but need its descriptor, call thegoogle-cloud-monitoring:list_metric_descriptorsMCP tool. If the tool is missing, refer to thecloud-monitoring-metric-selectionskill to configure the Cloud Monitoring MCP server. - Fallback: If the MCP tool cannot be configured, fall back to making a direct Cloud Monitoring API call.
- Vague Query: If the prompt is vague (for example,
- Identify Key Fields: From the retrieved descriptor, identify four key
schema attributes:
type: The Cloud Monitoring metric type string.metricKind:GAUGE,DELTA, orCUMULATIVE.valueType:INT64,DOUBLE,DISTRIBUTION, orBOOL.monitoredResourceTypes: Compatibleresource.typestrings required for resource scoping and grouping.
Resolve Resource Filters & Discovery Protocol
To filter data by a specific resource instance, apply these resource rules and discovery protocols:
- Monitored Resource Filter: Always include the
monitored_resource="<type>"filter in your query to prevent collisions across services that share metric names.- Example:
monitored_resource="gae_app"
- Example:
- Preserve User Literals (CRITICAL): ALWAYS use the literal resource names, namespaces, and IDs provided in the user's prompt. Do NOT override or replace these values with active resource names found during Cloud Monitoring discovery unless the user explicitly asked you to find active resources. Telemetry discovery must only be used to identify metric type names and label keys, not to override user input.
- Resource Identifier Mapping:
- Direct & Specific Keys: Use the most specific resource identifier
available. Example:
version_id,cluster_name. - Name-to-ID Resolution: If the user filters by a resource name
(such as
"instance-1"), but the resource schema uses numeric IDs (likeinstance_id), us
- Direct & Specific Keys: Use the most specific resource identifier
available. Example:
常见问题
它需要我的项目 ID 吗?
需要。它会询问项目 ID;如果你的请求中没有,它会检查环境。
它能找到指标吗?
不能。指标发现由单独的选择技能负责。
它适用于所有指标类型吗?
它设计用于将任何 Cloud Monitoring 指标和资源类型映射为 PromQL。
详情
作者的原始描述
Generates valid PromQL queries from Cloud Monitoring metric descriptors and resource parameters. Use when asked to create, generate, write, or format PromQL queries, PromQL strings, or PromQL aggregations for Cloud Monitoring metrics and resources. Don't use for raw metric discovery or metric selection.
repo: google/skills
热度
- GitHub 星标
- 22k
- 排名
- #10244
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
finding-google-skills
22k帮你的智能体为某项设置任务找到合适的 Google 指南,例如托管、数据库、存储、登录或 AI 模型服务。
gcloud
22k帮你的智能体编写并检查 Google Cloud gcloud 命令,在运行任何内容之前查阅准确的语法,避免猜测参数。
google-cloud-recipe-auth
22k引导你的智能体了解 Google Cloud 的身份与访问管理,包括人员和服务如何登录,以及它们各自获得哪些权限。
google-cloud-recipe-onboarding
22k带领新开发者完成在 Google Cloud 上的第一步,包括选择项目、关联计费,以及部署第一个资源。