aws_metrics_query
Query CloudWatch metrics via the GetMetricData API, supporting multiple queries, metric math expressions, and automatic period selection to stay within response limits.
Instructions
Query CloudWatch metrics via GetMetricData (the modern multi-metric / expression-capable API, not the legacy get-metric-statistics). Pass queries as a flat array of {id, namespace, metricName, dimensions?, statistic?, period?, expression?, label?}; the tool shapes them into MetricDataQueries for you. startTime/endTime accept ISO 8601 or relative shorthand ('15m', '1h', '1d', '1w'); endTime defaults to 'now'. Period is auto-picked from the time range when omitted (60s for <=3h, 300s for <=24h, 900s for <=15d, 3600s otherwise) to stay under CloudWatch's ~100,800-datapoint response cap. Returns {series: [{id, label?, timestamps, values, period?, statusCode?}], messages?, periodSeconds, profile, region, nextToken, hasMore}. Each series' period is the effective granularity for that query (its explicit period, or the auto-pick it inherited); it is omitted for an expression query that didn't set one. The top-level periodSeconds is always the auto-pick. When CloudWatch truncates a large response, hasMore is true and nextToken carries the resume cursor -- call again with nextToken set to fetch the next page (rare for typical agent queries that stay within the per-request cap). Use for 'show me the CPU on this instance for the last hour', 'sum lambda invocations across these 3 functions', or expression-based 'p99 latency divided by average latency' lookups.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | Override session region for this call. | |
| scanBy | No | Sort order for returned datapoints. Default 'TimestampDescending' (matches CloudWatch's default). | |
| endTime | No | ISO 8601 timestamp or relative shorthand. Default 'now'. | |
| profile | No | Override session profile for this call. | |
| queries | Yes | 1-100 queries. Each is either a metric-stat (namespace + metricName) or an expression. | |
| nextToken | No | Resume cursor from a previous call's `nextToken`. Omit for the first page. Forwarded as CloudWatch's NextToken; only meaningful when a prior call returned `hasMore: true`. | |
| startTime | No | ISO 8601 timestamp or relative shorthand ('15m', '1h', '1d', '1w'). Default '1h' (one hour ago). | |
| timeoutMs | No | Timeout in milliseconds. Default 60000 (60s). | |
| maxDataPoints | No | Target datapoint count. CloudWatch does not truncate to the first N points -- it widens (coarsens) the period server-side so the series aggregates down to fit this many points. CloudWatch's own ceiling is ~100,800; lower this to make CloudWatch return a coarser, smaller series. Forwarded as CloudWatch's MaxDatapoints (single 'p') field; the camelCase schema name follows this server's convention. |