Metric Selection (Service Query & Local Keyword Filtering)
Use this skill to identify the most relevant Cloud Monitoring metric
descriptors. It queries all metric descriptors for a target service from the API
and filters them locally inside the agent's context using keyword matching.
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-metric-selection)"
and append agent-skills/1.0 (skill:cloud-monitoring-metric-selection) to User-Agent headers.
CRITICAL RULES
- Always Query Live APIs: You MUST always retrieve the most up-to-date
metric descriptors dynamically by calling the
list_metric_descriptors MCP
tool.
- Mandatory Project ID and Resource Parameter Clarification: BEFORE
calling any API tools (such as
list_metric_descriptors), you MUST ensure
the GCP Project ID is provided in the prompt, URI, or environment context.
If the Project ID cannot be resolved, you MUST ask the user to clarify or
provide it BEFORE executing API queries. Do NOT run API queries against
unconfirmed default or placeholder project names (such as mock-project,
my-project-id, unused, or YOUR_PROJECT_ID).
- Fallback Reporting: If API calls fail and fallback sources (such as
public docs) are used, you MUST state the error, the fallback source, and
the risks of non-live data (such as potential staleness, missing custom
metrics, or schema mismatches).
Workflow
Step 1: Verify & Auto-Configure MCP
Check if any tool matching list_metric_descriptors (such as
google-cloud-monitoring:list_metric_descriptors,
mcp_google-cloud-monitoring_list_metric_descriptors, or a similar pattern)
is available in your active toolset.
Verify via Unique URL: To ensure you are calling the correct Cloud
Monitoring tool, confirm that the underlying MCP server configuration
points to: https://monitoring.googleapis.com/mcp.
If the tool is missing:
Locate the MCP configuration file for the user's environment. Check
common paths:
~/.gemini/config/mcp_config.json
~/.codeium/windsurf/mcp_config.json
cline_mcp_settings.json
claude_desktop_config.json
Directly update/merge the configuration file with the following server
configuration. CRITICAL: Merge the JSON object to preserve any
existing MCP servers in mcpServers. Do not overwrite the file.
"google-cloud-monitoring": {
"url": "https://monitoring.googleapis.com/mcp",
"authProviderType": "google_credentials",
"enabledTools": [
"list_metric_descriptors"
]
}
Print a clear message notifying the user that the
google-cloud-monitoring MCP server has been configured, and request
them to restart or start a new chat session to refresh tools. Stop
calling further tools and end the turn.
Step 2: Analyze Request & Extract Keywords
Resolve Project ID and Identifiers: Check for the GCP Project ID and
resource identifiers in the prompt, resource URIs, or environment context.
According to the CRITICAL RULES above, do NOT use placeholder project names.
Identify Service Prefix: Map target GCP services to their standard
prefix (such as compute, spanner, bigquery, storage).
Extract Metric Concepts: Extract metric keywords from user prompt (such
as "CPU", "memory", "bytes scanned", "latency", "connections") and map to
search substrings.
Example Query Analysis:
- User Prompt: "Check Cloud Storage bucket write throughput and request
count"
- Resource URI:
//storage.googleapis.com/projects/my-project/buckets/my-bucket
- Service Prefix:
storage (mapped to storage.googleapis.com)
- Metric Keywords:
write, throughput, request, count
- Mapped Substrings:
write, throughput, request_count, count
Step 3: Query Metric Descriptors via list_metric_descriptors Tool
Query all metric descriptors for each identified service prefix using the
list_metric_descriptors MCP tool (using pageSize: 200). Because Cloud
Monitoring filters do not allow combining multiple metric.type restrictions
with OR, you must initiate a separate query for each identified service
prefix (either sequentially or in parallel).
If any response includes a nextPageToken, you MUST make consecutive follow-up
calls passing pageToken until all remaining descriptors for that prefix are
retrieved before filtering.
Filter Pattern Construction: Map the target service domain to its appropriate
prefix style:
- Standard Google Cloud Services:
starts_with("<service_prefix>.googleapis.com/") (such as
bigquery.googleapis.com/, redis.googleapis.com/).
- Ops Agent (Guest OS):
starts_with("agent.googleapis.com/") (for guest
OS memory/disk metrics).
- Kubernetes / GKE Native:
starts_with("kubernetes.io/")
- Istio Service Mesh:
starts_with("istio.io/")
- Knative Serving / Autoscaler:
starts_with("knative.dev/")
- Custom / External Metrics: Use
starts_with("custom.googleapis.com/")
or starts_with("external.googleapis.com/").
Example Tool Call Payload: If both Spanner and Compute Engine are targeted in
the request, execute these two tool calls:
- Spanner query:
{
"name": "projects/my-project-id",
"filter": "metric.type = starts_with(\"spanner.googleapis.com/\")",
"pageSize": 200
}
- Compute Engine query:
{
"name": "projects/my-project-id",
"filter": "metric.type = starts_with(\"compute.googleapis.com/\")",
"pageSize": 200
}
Call the list_metric_descriptors tool with these payloads.
Step 4: Local Filtering & Fallback Protocol
Aggregate all descriptors returned from Step 3, and filter them locally inside
your LLM context:
- Keyword Filtering: Filter the list by matching your target metric
keywords (such as "cpu", "latency") against the
type, displayName, and
description fields of the descriptors.
- Resource Alignment: Check if the metric contains labels matching the
target resource granularity (such as checking for a
database label if
targeting a database resource). Do not attempt to dynamically match resource
type strings directly, as Cloud Monitoring resource mappings (like
Spanner databases mapping to spanner_instance) can be counter-intuitive.
Troubleshooting & API Fallbacks
If any tool call fails, times out, or returns empty results, use these
strategies:
- Case A: API Syntax Error: Examine the error message, correct the filter
syntax, and retry.
- Case B: Timeout / Rate Limits: Retry the call once with a smaller page
size (such as
pageSize: 20).
- Case C: Unrecoverable Failure / Empty List:
- Verify if the target service is enabled in the project.
- Search Google Cloud public documentation to verify standard metrics for
the service.
Step 5: Output Selected Metrics
For each service domain, return only the 5-15 key metrics directly relevant to
the user's intent.
You MUST report the selected metrics in clean Markdown tables, grouped by
service (that is, one table per service prefix). The table MUST include the
following columns: "Metric Type", "Display Name", "Description", "Metric Kind",
"Value Type", "Unit", and "Monitored Resource Types". Map the fields from the
Cloud Monitoring list_metric_descriptors tool call response objects
directly to the table columns:
- Metric Type: Map to the
type field (for example,
spanner.googleapis.com/instance/cpu/utilization).
- Display Name: Map to the
displayName field.
- Description: Map to the
description field.
- Metric Kind: Map to the
metricKind field (for example, GAUGE,
DELTA, CUMULATIVE).
- Value Type: Map to the
valueType field (for example, INT64,
DOUBLE, DISTRIBUTION, BOOL).
- Unit: Map to the
unit field (for example, 1, By, s, ms).
- Monitored Resource Types: Map to the
monitoredResourceTypes list field
(for example, ["spanner_instance"]).
Example Output Table:
| Metric Type |
Display Name |
Description |
Metric Kind |
Value Type |
Unit |
Monitored Resource Types |
spanner.googleapis.com/instance/cpu/utilization |
Instance CPU Utilization |
Fraction of allocated CPU currently in use. |
GAUGE |
DOUBLE |
1 |
["spanner_instance"] |
Reference Documentation & Links
1---2name: cloud-monitoring-metric-selection3metadata:4 source: https://skillmd.com/skills/google/cloud-monitoring-metric-selection5 version: "1.0.2"6 category: CloudObservabilityAndMonitoring7description: >-8 Retrieve, query, and identify relevant Cloud Monitoring metric descriptors on9 Google Cloud for a service or resource (such as Compute Engine, Spanner,10 BigQuery, Cloud Run, Cloud SQL, Pub/Sub, Cloud Storage, etc.). Use when asked11 to find, list, search, or discover GCP metric types, names, kind/value12 schemas, or descriptors.13---1415# Metric Selection (Service Query & Local Keyword Filtering)1617Use this skill to identify the most relevant Cloud Monitoring metric18descriptors. It queries all metric descriptors for a target service from the API19and filters them locally inside the agent's context using keyword matching.2021## Attribution2223**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you24MUST read [Usage Attribution](references/attribution.md). For commands executed25directly in the terminal (never in generated scripts, Terraform, or user code),26prefix `gcloud` with27`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-metric-selection)"`28and append `agent-skills/1.0 (skill:cloud-monitoring-metric-selection)` to `User-Agent` headers.2930## CRITICAL RULES3132* **Always Query Live APIs**: You MUST always retrieve the most up-to-date33 metric descriptors dynamically by calling the `list_metric_descriptors` MCP34 tool.35* **Mandatory Project ID and Resource Parameter Clarification**: BEFORE36 calling any API tools (such as `list_metric_descriptors`), you MUST ensure37 the GCP Project ID is provided in the prompt, URI, or environment context.38 If the Project ID cannot be resolved, you MUST ask the user to clarify or39 provide it BEFORE executing API queries. Do NOT run API queries against40 unconfirmed default or placeholder project names (such as `mock-project`,41 `my-project-id`, `unused`, or `YOUR_PROJECT_ID`).42* **Fallback Reporting**: If API calls fail and fallback sources (such as43 public docs) are used, you MUST state the error, the fallback source, and44 the risks of non-live data (such as potential staleness, missing custom45 metrics, or schema mismatches).4647## Workflow4849### Step 1: Verify & Auto-Configure MCP50511. Check if any tool matching `list_metric_descriptors` (such as52 `google-cloud-monitoring:list_metric_descriptors`,53 `mcp_google-cloud-monitoring_list_metric_descriptors`, or a similar pattern)54 is available in your active toolset.552. **Verify via Unique URL**: To ensure you are calling the correct Cloud56 Monitoring tool, confirm that the underlying MCP server configuration57 points to: **`https://monitoring.googleapis.com/mcp`**.583. If the tool is **missing**:5960 * Locate the MCP configuration file for the user's environment. Check61 common paths:62 - `~/.gemini/config/mcp_config.json`63 - `~/.codeium/windsurf/mcp_config.json`64 - `cline_mcp_settings.json`65 - `claude_desktop_config.json`66 * Directly update/merge the configuration file with the following server67 configuration. **CRITICAL**: Merge the JSON object to preserve any68 existing MCP servers in `mcpServers`. Do not overwrite the file.6970 ```json71 "google-cloud-monitoring": {72 "url": "https://monitoring.googleapis.com/mcp",73 "authProviderType": "google_credentials",74 "enabledTools": [75 "list_metric_descriptors"76 ]77 }78 ```7980 * Print a clear message notifying the user that the81 `google-cloud-monitoring` MCP server has been configured, and request82 them to restart or start a new chat session to refresh tools. Stop83 calling further tools and end the turn.8485### Step 2: Analyze Request & Extract Keywords86871. **Resolve Project ID and Identifiers**: Check for the GCP Project ID and88 resource identifiers in the prompt, resource URIs, or environment context.89 According to the CRITICAL RULES above, do NOT use placeholder project names.90912. **Identify Service Prefix**: Map target GCP services to their standard92 prefix (such as `compute`, `spanner`, `bigquery`, `storage`).93943. **Extract Metric Concepts**: Extract metric keywords from user prompt (such95 as "CPU", "memory", "bytes scanned", "latency", "connections") and map to96 search substrings.9798*Example Query Analysis:*99100* **User Prompt**: "Check Cloud Storage bucket write throughput and request101 count"102* **Resource URI**:103 `//storage.googleapis.com/projects/my-project/buckets/my-bucket`104* **Service Prefix**: `storage` (mapped to `storage.googleapis.com`)105* **Metric Keywords**: `write`, `throughput`, `request`, `count`106* **Mapped Substrings**: `write`, `throughput`, `request_count`, `count`107108### Step 3: Query Metric Descriptors via list_metric_descriptors Tool109110Query all metric descriptors for each identified service prefix using the111`list_metric_descriptors` MCP tool (using `pageSize: 200`). Because Cloud112Monitoring filters do not allow combining multiple `metric.type` restrictions113with `OR`, you must **initiate a separate query for each identified service114prefix** (either sequentially or in parallel).115116If any response includes a `nextPageToken`, you MUST make consecutive follow-up117calls passing `pageToken` until all remaining descriptors for that prefix are118retrieved before filtering.119120*Filter Pattern Construction:* Map the target service domain to its appropriate121prefix style:1221231. **Standard Google Cloud Services**:124 `starts_with("<service_prefix>.googleapis.com/")` (such as125 `bigquery.googleapis.com/`, `redis.googleapis.com/`).1262. **Ops Agent (Guest OS)**: `starts_with("agent.googleapis.com/")` (for guest127 OS memory/disk metrics).1283. **Kubernetes / GKE Native**: `starts_with("kubernetes.io/")`1294. **Istio Service Mesh**: `starts_with("istio.io/")`1305. **Knative Serving / Autoscaler**: `starts_with("knative.dev/")`1316. **Custom / External Metrics**: Use `starts_with("custom.googleapis.com/")`132 or `starts_with("external.googleapis.com/")`.133134*Example Tool Call Payload:* If both Spanner and Compute Engine are targeted in135the request, execute these two tool calls:1361371. Spanner query:138139```json140{141 "name": "projects/my-project-id",142 "filter": "metric.type = starts_with(\"spanner.googleapis.com/\")",143 "pageSize": 200144}145```1461471. Compute Engine query:148149```json150{151 "name": "projects/my-project-id",152 "filter": "metric.type = starts_with(\"compute.googleapis.com/\")",153 "pageSize": 200154}155```156157Call the `list_metric_descriptors` tool with these payloads.158159### Step 4: Local Filtering & Fallback Protocol160161Aggregate all descriptors returned from Step 3, and filter them locally inside162your LLM context:1631641. **Keyword Filtering**: Filter the list by matching your target metric165 keywords (such as "cpu", "latency") against the `type`, `displayName`, and166 `description` fields of the descriptors.1672. **Resource Alignment**: Check if the metric contains labels matching the168 target resource granularity (such as checking for a `database` label if169 targeting a database resource). Do not attempt to dynamically match resource170 type strings directly, as Cloud Monitoring resource mappings (like171 Spanner databases mapping to `spanner_instance`) can be counter-intuitive.172173#### Troubleshooting & API Fallbacks174175If any tool call fails, times out, or returns empty results, use these176strategies:177178* **Case A: API Syntax Error**: Examine the error message, correct the filter179 syntax, and retry.180* **Case B: Timeout / Rate Limits**: Retry the call once with a smaller page181 size (such as `pageSize: 20`).182* **Case C: Unrecoverable Failure / Empty List**:183 1. Verify if the target service is enabled in the project.184 2. Search Google Cloud public documentation to verify standard metrics for185 the service.186187### Step 5: Output Selected Metrics188189For each service domain, return only the 5-15 key metrics directly relevant to190the user's intent.191192You MUST report the selected metrics in clean Markdown tables, grouped by193service (that is, one table per service prefix). The table MUST include the194following columns: "Metric Type", "Display Name", "Description", "Metric Kind",195"Value Type", "Unit", and "Monitored Resource Types". Map the fields from the196Cloud Monitoring `list_metric_descriptors` tool call response objects197directly to the table columns:198199* **Metric Type**: Map to the `type` field (for example,200 `spanner.googleapis.com/instance/cpu/utilization`).201* **Display Name**: Map to the `displayName` field.202* **Description**: Map to the `description` field.203* **Metric Kind**: Map to the `metricKind` field (for example, `GAUGE`,204 `DELTA`, `CUMULATIVE`).205* **Value Type**: Map to the `valueType` field (for example, `INT64`,206 `DOUBLE`, `DISTRIBUTION`, `BOOL`).207* **Unit**: Map to the `unit` field (for example, `1`, `By`, `s`, `ms`).208* **Monitored Resource Types**: Map to the `monitoredResourceTypes` list field209 (for example, `["spanner_instance"]`).210211*Example Output Table:*212213Metric Type | Display Name | Description | Metric Kind | Value Type | Unit | Monitored Resource Types214:------------------------------------------------ | :----------------------- | :------------------------------------------ | :---------- | :--------- | :--- | :-----------------------215`spanner.googleapis.com/instance/cpu/utilization` | Instance CPU Utilization | Fraction of allocated CPU currently in use. | GAUGE | DOUBLE | 1 | `["spanner_instance"]`216217## Reference Documentation & Links218219* **Cloud Monitoring Metric List**:220 [GCP Metrics Documentation](https://cloud.google.com/monitoring/api/metrics_gcp)221* **MetricDescriptor MCP Tool Reference**:222 [MCP Tools Reference: monitoring.googleapis.com](https://docs.cloud.google.com/monitoring/api/ref_v3_mcp/mcp/tools_list/list_metric_descriptors)223* **Monitoring Filter Syntax Guide**:224 [Monitoring Filters](https://cloud.google.com/monitoring/api/v3/filters)