cloud-monitoring-list-time-series-request
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud Monitoring ListTimeSeries Request Generator
Cloud Monitoring ListTimeSeries 请求生成器
Use this skill to translate any Cloud Monitoring metric descriptor into valid,
production-ready REST API query parameters (, ,
, , , ).
ListTimeSeriesnamefilterinterval.startTimeinterval.endTimeaggregation.*view使用此技能可将任意Cloud Monitoring指标描述符转换为有效的、可用于生产环境的 REST API查询参数(、、、、、)。
ListTimeSeriesnamefilterinterval.startTimeinterval.endTimeaggregation.*viewCRITICAL 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 ). If the Project ID is missing and cannot be resolved, you MUST ask the user to clarify it before generating or executing
gcloud config get-value projectrequests. Do NOT use placeholders for project names.ListTimeSeries
- 必填项目ID确认:必须确保GCP项目ID存在于用户提示、输入负载或环境上下文(例如通过获取)中。如果项目ID缺失且无法确定,必须先请求用户明确提供,再生成或执行
gcloud config get-value project请求。请勿使用占位符代替项目名称。ListTimeSeries
Workflow
工作流程
Inspect Metric Metadata
检查指标元数据
- Use Provided Metric Metadata First: If the user's prompt already
includes metric metadata such as ,
metric.type,metricKind, resource types, or label keys, use those values directly instead of calling API tools.valueType - Discover Missing Metadata: If exact metric descriptors including
,
metric.type, andmetricKindare missing or underspecified, resolve the target metric's descriptor using one of these paths:valueType- Vague Query: If the prompt is vague, such as asking for VM CPU
usage, use the skill first to identify the specific metric type.
cloud-monitoring-metric-selection - Known Metric Type: If you already have the specific metric type name
such as , but need its descriptor, call the
compute.googleapis.com/instance/cpu/utilizationMCP tool. If the tool is missing, refer to thelist_metric_descriptorsskill to configure the Cloud Monitoring MCP server.cloud-monitoring-metric-selection - 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, such as asking for VM CPU
usage, use the
- Identify Key Fields: From the retrieved descriptor, identify key schema
attributes:
- : The Cloud Monitoring metric type string.
type - :
metricKind,GAUGE, orDELTA.CUMULATIVE - :
valueType,INT64,DOUBLE, orDISTRIBUTION.BOOL - : Compatible
monitoredResourceTypesstrings, for exampleresource.type. If multiple resource types are listed, select the specific["cloudsql_database", "cloudsql_instance"]that matches the target granularity of the user's request.resource.type
- 优先使用提供的指标元数据:如果用户提示中已包含指标元数据,如、
metric.type、metricKind、资源类型或标签键,请直接使用这些值,无需调用API工具。valueType - 发现缺失的元数据:如果缺少或未明确指定精确的指标描述符(包括、
metric.type和metricKind),请通过以下途径之一获取目标指标的描述符:valueType- 模糊查询:如果提示较为模糊(例如查询VM CPU使用率),请先使用技能确定具体的指标类型。
cloud-monitoring-metric-selection - 已知指标类型:如果已知道具体的指标类型名称(如)但需要其描述符,请调用
compute.googleapis.com/instance/cpu/utilizationMCP工具。如果该工具不可用,请参考list_metric_descriptors技能配置Cloud Monitoring MCP服务器。cloud-monitoring-metric-selection - 备选方案:如果无法配置MCP工具,请直接调用Cloud Monitoring API。
- 模糊查询:如果提示较为模糊(例如查询VM CPU使用率),请先使用
- 识别关键字段:从获取的描述符中识别关键架构属性:
- :Cloud Monitoring指标类型字符串。
type - :
metricKind、GAUGE或DELTA。CUMULATIVE - :
valueType、INT64、DOUBLE或DISTRIBUTION。BOOL - :兼容的
monitoredResourceTypes字符串,例如resource.type。如果列出了多个资源类型,请选择与用户请求的目标粒度匹配的特定["cloudsql_database", "cloudsql_instance"]。resource.type
Construct Monitoring Filter
构建监控过滤条件
The parameter is a mandatory string in Cloud Monitoring syntax that
restricts the query to a single and optional resource and metric
labels:
filtermetric.type-
Single Metric Type Restriction: EveryMUST specify exactly one
filterclause using an equality operator. For example:metric.typemetric.type = "compute.googleapis.com/instance/cpu/utilization"
-
Monitored Resource Type Filter: MUST include thefilter when the target resource granularity is known, preventing collisions across services that share metric types or sub-resources. For example:
resource.typemetric.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 prefix. For example:
resource.labels.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
prefix. For example:
metric.labels.metric.labels.state != "free"metric.labels.instance_name = "instance-1"
- Prefix resource-level dimensions, such as instance ID, zone, project,
database ID, or subscription ID, with the
-
Resource Name versus ID Resolution:
- If the user specifies a human-readable GCE VM instance name such as
, but
"instance-1"expects a numeric ID, you MUST filter using eitherresource.labels.instance_idormetric.labels.instance_name = "instance-1".metadata.system_labels.name = "instance-1" - Do NOT use or
resource.metadata.name. This prefix is invalid in Cloud Monitoring filter syntax.resource.metadata.* - Do NOT assign a string instance name directly to
unless the resource type explicitly uses string IDs.
resource.labels.instance_id
- If the user specifies a human-readable GCE VM instance name such as
-
Database Identifier Labels: Database labels such asfor Cloud SQL and Spanner, or
database_idfor BigQuery, use composite keys formatted asdataset_id. For example:<project_id>:<instance_name>.resource.labels.database_id = "my-project:foo" -
Ops Agent Metrics State Label Filtering: Forand
agent.googleapis.com/memory/percent_usedmetrics, you MUST useagent.googleapis.com/disk/percent_used. Do NOT filter bymetric.labels.state != "free".metric.labels.state = "used"
filtermetric.type-
单一指标类型限制:每个必须使用相等运算符指定恰好一个
filter子句。例如:metric.typemetric.type = "compute.googleapis.com/instance/cpu/utilization"
-
受监控资源类型过滤:当已知目标资源粒度时,必须包含过滤条件,以避免跨服务共享指标类型或子资源时产生冲突。例如:
resource.typemetric.type = "cloudsql.googleapis.com/database/cpu/utilization" AND resource.type = "cloudsql_database"
-
保留用户提供的字面量和ID:必须使用用户提供的字面资源名称、ID、可用区和项目参数,不得修改。除非用户明确要求,否则请勿用指标元数据发现过程中找到的活跃资源覆盖或替换用户指定的标识符。
-
标签类型前缀:
- 资源级维度(如实例ID、可用区、项目、数据库ID或订阅ID)需添加前缀。例如:
resource.labels.resource.labels.instance_id = "123456789"resource.labels.database_id = "my-project:my-instance"
- 指标级维度(如状态、命令、响应码或存储在指标中的实例名称元数据)需添加前缀。例如:
metric.labels.metric.labels.state != "free"metric.labels.instance_name = "instance-1"
- 资源级维度(如实例ID、可用区、项目、数据库ID或订阅ID)需添加
-
资源名称与ID的转换:
- 如果用户指定了GCE VM实例的可读名称(如),但
"instance-1"需要数字ID,则必须使用resource.labels.instance_id或metric.labels.instance_name = "instance-1"进行过滤。metadata.system_labels.name = "instance-1" - 请勿使用或
resource.metadata.name。该前缀在Cloud Monitoring过滤语法中无效。resource.metadata.* - 除非资源类型明确使用字符串ID,否则请勿将字符串实例名称直接赋值给。
resource.labels.instance_id
- 如果用户指定了GCE VM实例的可读名称(如
-
数据库标识符标签:数据库标签(如Cloud SQL和Spanner的,或BigQuery的
database_id)使用复合键,格式为dataset_id。例如:<project_id>:<instance_name>。resource.labels.database_id = "my-project:foo" -
Ops Agent指标状态标签过滤:对于和
agent.googleapis.com/memory/percent_used指标,必须使用agent.googleapis.com/disk/percent_used。请勿使用metric.labels.state != "free"进行过滤。metric.labels.state = "used"
Choose Aggregation Structure
选择聚合结构
Select the , , , and
according to the metric properties and visualization goal:
perSeriesAlignercrossSeriesReducergroupByFieldsalignmentPeriod- Consult the Aggregations Reference: You MUST include both
and
perSeriesAlignerin thecrossSeriesReducerquery parameters of every request. Read and follow the Cloud Monitoring ListTimeSeries Basic Aggregations Reference to select the exactaggregationandperSeriesAlignercombinations 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 bycrossSeriesReducer.state != "free" - Grouping Fields and Resource Granularity: When is specified as anything other than
crossSeriesReducer, list the exact labels to preserve. When querying multi-instance resources like VMs, databases, or subscriptions, include the primary resource identifier inREDUCE_NONE. For example, usegroupByFieldsfor VMs orresource.labels.instance_idfor databases. This prevents collapsing separate resource streams into a single global aggregate.resource.labels.database_id - Alignment Period Determination: Calculate the query lookback duration
from minus
endTime, ensuringstartTimeprecedesstartTime. IfendTime, flag an error before computing duration. SetendTime <= startTimeaccording to Cloud Console default fine granularity standards:alignmentPeriod- 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: is omitted only when
alignmentPeriodis set toperSeriesAligner.ALIGN_NONE
- Duration <= 110 minutes: Set
根据指标属性和可视化目标选择、、和:
perSeriesAlignercrossSeriesReducergroupByFieldsalignmentPeriod- 参考聚合文档:每个请求的查询参数中必须同时包含
aggregation和perSeriesAligner。请阅读并遵循Cloud Monitoring ListTimeSeries基础聚合参考,根据指标的Metric Kind和Value Type组合选择确切的crossSeriesReducer和perSeriesAligner组合,并针对利用率指标、计数器、分布以及基于状态的仪表盘(如按crossSeriesReducer过滤的内存指标)应用强制性SRE规则。state != "free" - 分组字段与资源粒度:当设置为
crossSeriesReducer以外的值时,列出需要保留的精确标签。查询多实例资源(如VM、数据库或订阅)时,请在REDUCE_NONE中包含主要资源标识符。例如,对VM使用groupByFields,对数据库使用resource.labels.instance_id。这样可以避免将独立的资源流合并为单个全局聚合。resource.labels.database_id - 对齐周期确定:根据减去
endTime计算查询回溯时长,确保startTime早于startTime。如果endTime,请在计算时长前标记错误。根据Cloud Console默认的精细粒度标准设置endTime <= startTime:alignmentPeriod- 时长 ≤ 110分钟:设置。
alignmentPeriod = "60s" - 时长 ≤ 23小时:设置。
alignmentPeriod = "300s" - 时长 ≤ 6天:设置。
alignmentPeriod = "3600s" - 时长 ≤ 23天:设置。
alignmentPeriod = "10800s" - 时长 ≤ 80天:设置。
alignmentPeriod = "21600s" - 时长 ≤ 180天:设置。
alignmentPeriod = "43200s" - 时长 ≤ 350天:设置。
alignmentPeriod = "86400s" - 时长 ≤ 500天:设置。
alignmentPeriod = "172800s" - 省略规则:仅当设置为
perSeriesAligner时,才省略ALIGN_NONE。alignmentPeriod
- 时长 ≤ 110分钟:设置
Format Valid Request
格式化有效请求
Present the generated REST query parameters. For example:
ListTimeSeriesjson
{
"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 parameters with the
aggregation,perSeriesAligner,crossSeriesReducer, and optionalalignmentPeriodvalues determined during aggregation selection.groupByFields - Interval Requirements: and
startTimeMUST be valid RFC 3339 and ISO 8601 timestamps such asendTime. If not explicitly provided by the user, dynamically compute a one-hour lookback interval ending at the current time, where"YYYY-MM-DDTHH:MM:SSZ"is the present moment andendTimeis one hour prior. Do NOT hardcode static dates from examples.startTime - Alignment Period Requirement: Determine from the lookback duration of
alignmentPeriodminusendTimeusing the mapping above. For the default one-hour lookback interval,startTimeisalignmentPeriod."60s" - View Requirement: MUST default to when time series data points are needed, or
"FULL"when inspecting metadata and series identities only."HEADERS"
展示生成的 REST查询参数。例如:
ListTimeSeriesjson
{
"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"
}- 聚合要求:使用聚合选择阶段确定的、
perSeriesAligner、crossSeriesReducer和可选的alignmentPeriod值填充groupByFields参数。aggregation - 时间间隔要求:和
startTime必须是有效的RFC 3339和ISO 8601时间戳,例如endTime。如果用户未明确提供,请动态计算以当前时间为结束时间的一小时回溯间隔,其中"YYYY-MM-DDTHH:MM:SSZ"为当前时刻,endTime为一小时前。请勿硬编码示例中的静态日期。startTime - 对齐周期要求:根据减去
endTime的回溯时长,使用上述映射确定startTime。对于默认的一小时回溯间隔,alignmentPeriod为alignmentPeriod。"60s" - 视图要求:当需要时间序列数据点时,必须默认设置为;仅当需要检查元数据和序列标识时,设置为
"FULL"。"HEADERS"
Validate Request via REST API
通过REST API验证请求
Always validate the generated request parameters against live Cloud Monitoring
telemetry before returning the final output. DO NOT call the
MCP tool. Perform an HTTP GET request directly to the Cloud Monitoring v3 REST
API using with for all query fields (, ,
, , ,
, , and
). An HTTP 200 OK response confirms that your filter and
aggregation settings are valid.
list_timeseriescurl -s -H "Authorization: Bearer \$(gcloud auth print-access-token)" -G--data-urlencodenamefilterinterval.startTimeinterval.endTimeaggregation.alignmentPeriodaggregation.perSeriesAligneraggregation.crossSeriesReducerview=HEADERS在返回最终输出前,始终根据实时Cloud Monitoring遥测数据验证生成的请求参数。请勿调用 MCP工具。请使用直接向Cloud Monitoring v3 REST API发送HTTP GET请求,并使用处理所有查询字段(、、、、、、和)。HTTP 200 OK响应表示过滤条件和聚合设置有效。
list_timeseriescurl -s -H "Authorization: Bearer \$(gcloud auth print-access-token)" -G--data-urlencodenamefilterinterval.startTimeinterval.endTimeaggregation.alignmentPeriodaggregation.perSeriesAligneraggregation.crossSeriesReducerview=HEADERSReferences
参考资料
- Cloud Monitoring ListTimeSeries Basic Aggregations Reference
- Cloud Monitoring Monitored Resource Types Reference
- Cloud Monitoring Filter Syntax
- Cloud Monitoring REST API Reference: projects.timeSeries.list
- Cloud Monitoring ListTimeSeries基础聚合参考
- Cloud Monitoring受监控资源类型参考
- Cloud Monitoring过滤语法
- Cloud Monitoring REST API参考:projects.timeSeries.list