Loki: Query Metric
loki_query_metricEvaluate LogQL metric queries at an instant to answer how-many or which-series questions with aggregated counts, rates, or totals over a time window.
Instructions
Evaluate a LogQL metric query at one instant: a count, rate or total over a window written into the query, e.g. errors per namespace over the last hour sum by (namespace) (count_over_time({namespace=~".+"} |= "error" [1h])), or the top 10 topk(10, ...). The right tool for 'how many / which ones' questions — far cheaper than reading lines with loki_query_logs. Labels shared by every series come once as common_labels. Series come back largest value first: LogQL's topk() picks the top N but does not order them.
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"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sort | No | value: largest first, applied before `limit` cuts, so a cut keeps the biggest. labels: Loki's own order. | value |
| time | No | Evaluation time: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z, nanosecond fractions kept) or unix seconds/nanoseconds. Defaults to now. | |
| limit | No | Maximum series to return (1-2000). Defaults to 100. Use topk() in the query to keep the largest instead of raising this. | |
| 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. | |
| precision | No | Significant digits to round fractional values to (whole numbers are never rounded). Defaults to 4; 0 returns the exact value. |