aws_metrics_query
Query CloudWatch metrics across AWS services with multi-metric and expression support, relative time ranges, and automatic period selection.
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 relative shorthand ('15m', '1h', '1d', '1w'), 'now', or ISO 8601 WITH an explicit offset ('2026-05-16T10:00:00Z' / '...-04:00' -- an offset-less date-time is rejected rather than silently read in the host's local zone; a date-only '2026-05-16' is read as UTC midnight); 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 | Same forms as startTime: relative shorthand, 'now', or ISO 8601 with an explicit offset. 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 | Relative shorthand ('15m', '1h', '1d', '1w'), 'now', or an ISO 8601 timestamp with an explicit offset ('2026-05-16T10:00:00Z', '2026-05-16T10:00:00-04:00'). A date-only '2026-05-16' is read as UTC midnight; an offset-less date-time is rejected (it would resolve in the server host's local zone). A bare number like '5' is rejected -- write '5m'. 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. Setting it also tells this tool the response is bounded, so a wide range or large batch that would otherwise be rejected locally against that ceiling is passed through (a value ABOVE the ceiling bounds nothing and is still rejected). Forwarded as CloudWatch's MaxDatapoints (single 'p') field; the camelCase schema name follows this server's convention. |