Loki: Query Metric Range
loki_query_metric_rangeEvaluate LogQL metric queries over a time range to spot log-volume or error-rate spikes, when they started, and which service they came from, with per-series stats and optional step values.
Instructions
Evaluate a LogQL metric query over a time range, for how log volume or error rates changed: a spike, when it started, which service it came from. Each series comes back with stats (min, max, avg, last) and, with view=values, one value per step on a shared grid given by start and step (null where there was nothing). The step is picked for about 60 points unless given; the range in the query ([5m]) is independent of it, and usually should match it. Aggregate with sum by — one series per stream is rarely what you want and quickly hits max_query_series.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>"
},
"name": "loki_query_metric_range"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | Range end: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z, nanosecond fractions kept) or unix seconds/nanoseconds. Defaults to now. | |
| sort | No | Order of series, applied before `limit` cuts: labels keeps Loki's order; max/avg/last rank highest first, so a cut keeps the biggest. | labels |
| step | No | Resolution, as a duration (30s, 5m, 1h) or seconds. Defaults to a round step giving about 60 points. | |
| view | No | values: stats plus the value at every step. stats: min/max/avg/last only, about a tenth of the size — use it to survey many series before plotting a few. | values |
| limit | No | Maximum series to return (1-500). Defaults to 20. | |
| query | Yes | A LogQL metric query: a range aggregation over a log query, usually aggregated by a label, e.g. `sum by (namespace) (count_over_time({namespace=~".+"} |= "error" [5m]))` or `sum by (status) (rate({app="nginx"} | json [1m]))`. Unwrapped values: `avg_over_time({app="api"} | json | unwrap duration_ms [5m])`. Always aggregate (sum by) unless you want one series per stream. | |
| start | No | Range start: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z, nanosecond fractions kept) or unix seconds/nanoseconds. Defaults to now-1h. | |
| precision | No | Significant digits to round fractional values to (whole numbers are never rounded). Defaults to 4; 0 returns the exact value. |