Cloud Monitoring ListTimeSeries Request Generator
Use this skill to translate any Cloud Monitoring metric descriptor into valid,
production-ready ListTimeSeries REST API query parameters (name, filter,
interval.startTime, interval.endTime, aggregation.*, view).
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-list-time-series-request)"
and append agent-skills/1.0 (skill:cloud-monitoring-list-time-series-request) to User-Agent headers.
CRITICAL RULES
- Mandatory Project ID Clarification: You MUST ensure the GCP Project ID
is present in the user prompt, input payload, or environment context (such
as via
gcloud config get-value project). If the Project ID is missing and
cannot be resolved, you MUST ask the user to clarify it before generating or
executing ListTimeSeries requests. Do NOT use placeholders for project
names.
Workflow
Inspect Metric Metadata
- Use Provided Metric Metadata First: If the user's prompt already
includes metric metadata such as
metric.type, metricKind, valueType,
resource types, or label keys, use those values directly instead of calling
API tools.
- Discover Missing Metadata: If exact metric descriptors including
metric.type, metricKind, and valueType are missing or underspecified,
resolve the target metric's descriptor using one of these paths:
- Vague Query: If the prompt is vague, such as asking for VM CPU
usage, use the
cloud-monitoring-metric-selection skill first to
identify the specific metric type.
- Known Metric Type: If you already have the specific metric type name
such as
compute.googleapis.com/instance/cpu/utilization, but need its
descriptor, call the list_metric_descriptors MCP tool. If the tool is
missing, refer to the cloud-monitoring-metric-selection skill 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.
- Identify Key Fields: From the retrieved descriptor, identify key schema
attributes:
type: The Cloud Monitoring metric type string.
metricKind: GAUGE, DELTA, or CUMULATIVE.
valueType: INT64, DOUBLE, DISTRIBUTION, or BOOL.
monitoredResourceTypes: Compatible resource.type strings, for
example ["cloudsql_database", "cloudsql_instance"]. If multiple
resource types are listed, select the specific resource.type that
matches the target granularity of the user's request.
Construct Monitoring Filter
The filter parameter is a mandatory string in Cloud Monitoring syntax that
restricts the query to a single metric.type and optional resource and metric
labels:
Single Metric Type Restriction: Every filter MUST specify exactly one
metric.type clause using an equality operator. For example:
metric.type = "compute.googleapis.com/instance/cpu/utilization"
Monitored Resource Type Filter: MUST include the resource.type filter
when the target resource granularity is known, preventing collisions across
services that share metric types or sub-resources. For example:
metric.type = "cloudsql.googleapis.com/database/cpu/utilization" AND resource.type = "cloudsql_database"
Preserve User Literals and IDs: You MUST use literal resource names,
IDs, zones, and project parameters provided by the user without alteration.
Do NOT override or replace user-specified identifiers with active resources
found during metric metadata discovery unless explicitly requested.
Label Type Prefixing:
- Prefix resource-level dimensions, such as instance ID, zone, project,
database ID, or subscription ID, with the
resource.labels. prefix. For
example:
resource.labels.instance_id = "123456789"
resource.labels.database_id = "my-project:my-instance"
- Prefix metric-level dimensions, such as state, command, response code,
or instance name metadata when stored on the metric, with the
metric.labels. prefix. For example:
metric.labels.state != "free"
metric.labels.instance_name = "instance-1"
Resource Name versus ID Resolution:
- If the user specifies a human-readable GCE VM instance name such as
"instance-1", but resource.labels.instance_id expects a numeric ID,
you MUST filter using either metric.labels.instance_name = "instance-1" or metadata.system_labels.name = "instance-1".
- Do NOT use
resource.metadata.name or resource.metadata.*. This
prefix is invalid in Cloud Monitoring filter syntax.
- Do NOT assign a string instance name directly to
resource.labels.instance_id unless the resource type explicitly uses
string IDs.
Database Identifier Labels: Database labels such as database_id for
Cloud SQL and Spanner, or dataset_id for BigQuery, use composite keys
formatted as <project_id>:<instance_name>. For example:
resource.labels.database_id = "my-project:foo".
Ops Agent Metrics State Label Filtering: For
agent.googleapis.com/memory/percent_used and
agent.googleapis.com/disk/percent_used metrics, you MUST use
metric.labels.state != "free". Do NOT filter by metric.labels.state = "used".
Choose Aggregation Structure
Select the perSeriesAligner, crossSeriesReducer, groupByFields, and
alignmentPeriod according to the metric properties and visualization goal:
- Consult the Aggregations Reference: You MUST include both
perSeriesAligner and crossSeriesReducer in the aggregation query
parameters of every request. Read and follow the
Cloud Monitoring ListTimeSeries Basic Aggregations Reference
to select the exact perSeriesAligner and crossSeriesReducer combinations
for your metric's Metric Kind and Value Type pairing, and to apply mandatory
SRE rules for utilization metrics, counters, distributions, and state-based
gauges such as memory filtered by state != "free".
- Grouping Fields and Resource Granularity: When
crossSeriesReducer is
specified as anything other than REDUCE_NONE, list the exact labels to
preserve. When querying multi-instance resources like VMs, databases, or
subscriptions, include the primary resource identifier in groupByFields.
For example, use resource.labels.instance_id for VMs or
resource.labels.database_id for databases. This prevents collapsing
separate resource streams into a single global aggregate.
- Alignment Period Determination: Calculate the query lookback duration
from
endTime minus startTime, ensuring startTime precedes endTime.
If endTime <= startTime, flag an error before computing duration. Set
alignmentPeriod according to Cloud Console default fine granularity
standards:
- Duration <= 110 minutes: Set
alignmentPeriod = "60s".
- Duration <= 23 hours: Set
alignmentPeriod = "300s".
- Duration <= 6 days: Set
alignmentPeriod = "3600s".
- Duration <= 23 days: Set
alignmentPeriod = "10800s".
- Duration <= 80 days: Set
alignmentPeriod = "21600s".
- Duration <= 180 days: Set
alignmentPeriod = "43200s".
- Duration <= 350 days: Set
alignmentPeriod = "86400s".
- Duration <= 500 days: Set
alignmentPeriod = "172800s".
- Omission Rule:
alignmentPeriod is omitted only when
perSeriesAligner is set to ALIGN_NONE.
Format Valid Request
Present the generated ListTimeSeries REST query parameters. For example:
{
"name": "projects/<project_id>",
"filter": "metric.type = \"<metric_type>\" AND resource.type = \"<resource_type>\"",
"interval": {
"startTime": "<iso_8601_start>",
"endTime": "<iso_8601_end>"
},
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": [
"resource.labels.zone"
]
},
"view": "FULL"
}
- Aggregation Requirements: Populate the
aggregation parameters with the
perSeriesAligner, crossSeriesReducer, alignmentPeriod, and optional
groupByFields values determined during aggregation selection.
- Interval Requirements:
startTime and endTime MUST be valid RFC 3339
and ISO 8601 timestamps such as "YYYY-MM-DDTHH:MM:SSZ". If not explicitly
provided by the user, dynamically compute a one-hour lookback interval
ending at the current time, where endTime is the present moment and
startTime is one hour prior. Do NOT hardcode static dates from examples.
- Alignment Period Requirement: Determine
alignmentPeriod from the
lookback duration of endTime minus startTime using the mapping above.
For the default one-hour lookback interval, alignmentPeriod is "60s".
- View Requirement: MUST default to
"FULL" when time series data points
are needed, or "HEADERS" when inspecting metadata and series identities
only.
Validate Request via list_timeseries MCP Tool
You MUST validate the generated request parameters against live Cloud Monitoring
telemetry before returning the final output. Call the list_timeseries MCP tool
passing all generated query parameters (name, filter, interval,
aggregation). When validating you MUST set view="HEADERS" to minimize
latency and payload size while verifying request structure. A response without
API errors confirms that your filter and aggregation settings are valid.
If the list_timeseries tool is unavailable, fall back to a direct API call.
References
1---2name: cloud-monitoring-list-time-series-request3metadata:4 source: https://skillmd.com/skills/google/cloud-monitoring-list-time-series-request5 version: "1.0.1"6 category: CloudObservabilityAndMonitoring7description: >-8 Generates valid Cloud Monitoring ListTimeSeries requests and aggregation9 specifications from metric descriptors and resource parameters. Use when asked10 to create, generate, format, or build ListTimeSeries requests, JSON payloads,11 filter expressions, or aligner/reducer aggregations for Cloud Monitoring12 metrics and charts. Don't use for metric discovery or metric selection.13---1415# Cloud Monitoring ListTimeSeries Request Generator1617Use this skill to translate any Cloud Monitoring metric descriptor into valid,18production-ready `ListTimeSeries` REST API query parameters (`name`, `filter`,19`interval.startTime`, `interval.endTime`, `aggregation.*`, `view`).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-list-time-series-request)"`28and append `agent-skills/1.0 (skill:cloud-monitoring-list-time-series-request)` to `User-Agent` headers.2930## CRITICAL RULES3132* **Mandatory Project ID Clarification**: You MUST ensure the GCP Project ID33 is present in the user prompt, input payload, or environment context (such34 as via `gcloud config get-value project`). If the Project ID is missing and35 cannot be resolved, you MUST ask the user to clarify it before generating or36 executing `ListTimeSeries` requests. Do NOT use placeholders for project37 names.3839## Workflow4041### Inspect Metric Metadata42431. **Use Provided Metric Metadata First**: If the user's prompt already44 includes metric metadata such as `metric.type`, `metricKind`, `valueType`,45 resource types, or label keys, use those values directly instead of calling46 API tools.472. **Discover Missing Metadata**: If exact metric descriptors including48 `metric.type`, `metricKind`, and `valueType` are missing or underspecified,49 resolve the target metric's descriptor using one of these paths:50 * **Vague Query**: If the prompt is vague, such as asking for VM CPU51 usage, use the `cloud-monitoring-metric-selection` skill first to52 identify the specific metric type.53 * **Known Metric Type**: If you already have the specific metric type name54 such as `compute.googleapis.com/instance/cpu/utilization`, but need its55 descriptor, call the `list_metric_descriptors` MCP tool. If the tool is56 missing, refer to the `cloud-monitoring-metric-selection` skill to57 configure the Cloud Monitoring MCP server.58 * **Fallback**: If the MCP tool cannot be configured, fall back to making59 a direct Cloud Monitoring API call.603. **Identify Key Fields**: From the retrieved descriptor, identify key schema61 attributes:62 * **`type`**: The Cloud Monitoring metric type string.63 * **`metricKind`**: `GAUGE`, `DELTA`, or `CUMULATIVE`.64 * **`valueType`**: `INT64`, `DOUBLE`, `DISTRIBUTION`, or `BOOL`.65 * **`monitoredResourceTypes`**: Compatible `resource.type` strings, for66 example `["cloudsql_database", "cloudsql_instance"]`. If multiple67 resource types are listed, select the specific `resource.type` that68 matches the target granularity of the user's request.6970--------------------------------------------------------------------------------7172### Construct Monitoring Filter7374The `filter` parameter is a mandatory string in Cloud Monitoring syntax that75restricts the query to a single `metric.type` and optional resource and metric76labels:77781. **Single Metric Type Restriction**: Every `filter` MUST specify exactly one79 `metric.type` clause using an equality operator. For example:80 * `metric.type = "compute.googleapis.com/instance/cpu/utilization"`812. **Monitored Resource Type Filter**: MUST include the `resource.type` filter82 when the target resource granularity is known, preventing collisions across83 services that share metric types or sub-resources. For example:84 * `metric.type = "cloudsql.googleapis.com/database/cpu/utilization" AND85 resource.type = "cloudsql_database"`863. **Preserve User Literals and IDs**: You MUST use literal resource names,87 IDs, zones, and project parameters provided by the user without alteration.88 Do NOT override or replace user-specified identifiers with active resources89 found during metric metadata discovery unless explicitly requested.90914. **Label Type Prefixing**:9293 * Prefix resource-level dimensions, such as instance ID, zone, project,94 database ID, or subscription ID, with the `resource.labels.` prefix. For95 example:96 * `resource.labels.instance_id = "123456789"`97 * `resource.labels.database_id = "my-project:my-instance"`98 * Prefix metric-level dimensions, such as state, command, response code,99 or instance name metadata when stored on the metric, with the100 `metric.labels.` prefix. For example:101 * `metric.labels.state != "free"`102 * `metric.labels.instance_name = "instance-1"`1031045. **Resource Name versus ID Resolution**:105106 * If the user specifies a human-readable GCE VM instance name such as107 `"instance-1"`, but `resource.labels.instance_id` expects a numeric ID,108 you MUST filter using either `metric.labels.instance_name =109 "instance-1"` or `metadata.system_labels.name = "instance-1"`.110 * Do NOT use `resource.metadata.name` or `resource.metadata.*`. This111 prefix is invalid in Cloud Monitoring filter syntax.112 * Do NOT assign a string instance name directly to113 `resource.labels.instance_id` unless the resource type explicitly uses114 string IDs.1151166. **Database Identifier Labels**: Database labels such as `database_id` for117 Cloud SQL and Spanner, or `dataset_id` for BigQuery, use composite keys118 formatted as `<project_id>:<instance_name>`. For example:119 `resource.labels.database_id = "my-project:foo"`.1201217. **Ops Agent Metrics State Label Filtering**: For122 `agent.googleapis.com/memory/percent_used` and123 `agent.googleapis.com/disk/percent_used` metrics, you MUST use124 `metric.labels.state != "free"`. Do NOT filter by `metric.labels.state =125 "used"`.126127--------------------------------------------------------------------------------128129### Choose Aggregation Structure130131Select the `perSeriesAligner`, `crossSeriesReducer`, `groupByFields`, and132`alignmentPeriod` according to the metric properties and visualization goal:1331341. **Consult the Aggregations Reference**: You MUST include both135 `perSeriesAligner` and `crossSeriesReducer` in the `aggregation` query136 parameters of every request. Read and follow the137 [Cloud Monitoring ListTimeSeries Basic Aggregations Reference](references/basic_aggregations.md)138 to select the exact `perSeriesAligner` and `crossSeriesReducer` combinations139 for your metric's Metric Kind and Value Type pairing, and to apply mandatory140 SRE rules for utilization metrics, counters, distributions, and state-based141 gauges such as memory filtered by `state != "free"`.1422. **Grouping Fields and Resource Granularity**: When `crossSeriesReducer` is143 specified as anything other than `REDUCE_NONE`, list the exact labels to144 preserve. When querying multi-instance resources like VMs, databases, or145 subscriptions, include the primary resource identifier in `groupByFields`.146 For example, use `resource.labels.instance_id` for VMs or147 `resource.labels.database_id` for databases. This prevents collapsing148 separate resource streams into a single global aggregate.1493. **Alignment Period Determination**: Calculate the query lookback duration150 from `endTime` minus `startTime`, ensuring `startTime` precedes `endTime`.151 If `endTime <= startTime`, flag an error before computing duration. Set152 `alignmentPeriod` according to Cloud Console default fine granularity153 standards:154 * **Duration <= 110 minutes**: Set `alignmentPeriod = "60s"`.155 * **Duration <= 23 hours**: Set `alignmentPeriod = "300s"`.156 * **Duration <= 6 days**: Set `alignmentPeriod = "3600s"`.157 * **Duration <= 23 days**: Set `alignmentPeriod = "10800s"`.158 * **Duration <= 80 days**: Set `alignmentPeriod = "21600s"`.159 * **Duration <= 180 days**: Set `alignmentPeriod = "43200s"`.160 * **Duration <= 350 days**: Set `alignmentPeriod = "86400s"`.161 * **Duration <= 500 days**: Set `alignmentPeriod = "172800s"`.162 * **Omission Rule**: `alignmentPeriod` is omitted only when163 `perSeriesAligner` is set to `ALIGN_NONE`.164165--------------------------------------------------------------------------------166167### Format Valid Request168169Present the generated `ListTimeSeries` REST query parameters. For example:170171```json172{173 "name": "projects/<project_id>",174 "filter": "metric.type = \"<metric_type>\" AND resource.type = \"<resource_type>\"",175 "interval": {176 "startTime": "<iso_8601_start>",177 "endTime": "<iso_8601_end>"178 },179 "aggregation": {180 "alignmentPeriod": "60s",181 "perSeriesAligner": "ALIGN_RATE",182 "crossSeriesReducer": "REDUCE_SUM",183 "groupByFields": [184 "resource.labels.zone"185 ]186 },187 "view": "FULL"188}189```190191* **Aggregation Requirements**: Populate the `aggregation` parameters with the192 `perSeriesAligner`, `crossSeriesReducer`, `alignmentPeriod`, and optional193 `groupByFields` values determined during aggregation selection.194* **Interval Requirements**: `startTime` and `endTime` MUST be valid RFC 3339195 and ISO 8601 timestamps such as `"YYYY-MM-DDTHH:MM:SSZ"`. If not explicitly196 provided by the user, dynamically compute a one-hour lookback interval197 ending at the current time, where `endTime` is the present moment and198 `startTime` is one hour prior. Do NOT hardcode static dates from examples.199* **Alignment Period Requirement**: Determine `alignmentPeriod` from the200 lookback duration of `endTime` minus `startTime` using the mapping above.201 For the default one-hour lookback interval, `alignmentPeriod` is `"60s"`.202* **View Requirement**: MUST default to `"FULL"` when time series data points203 are needed, or `"HEADERS"` when inspecting metadata and series identities204 only.205206--------------------------------------------------------------------------------207208### Validate Request via list_timeseries MCP Tool209210You MUST validate the generated request parameters against live Cloud Monitoring211telemetry before returning the final output. Call the `list_timeseries` MCP tool212passing all generated query parameters (`name`, `filter`, `interval`,213`aggregation`). When validating you MUST set `view="HEADERS"` to minimize214latency and payload size while verifying request structure. A response without215API errors confirms that your filter and aggregation settings are valid.216217If the `list_timeseries` tool is unavailable, fall back to a direct API call.218219--------------------------------------------------------------------------------220221## References222223* [Cloud Monitoring ListTimeSeries Basic Aggregations Reference](references/basic_aggregations.md)224* [Cloud Monitoring Monitored Resource Types Reference](https://docs.cloud.google.com/monitoring/api/resources.md.txt)225* [Cloud Monitoring Filter Syntax](https://docs.cloud.google.com/monitoring/api/v3/filters.md.txt)226* [Cloud Monitoring REST API Reference: projects.timeSeries.list](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list.md.txt)