On this page
timechart command
Aggregate into fixed time buckets. The shape a dashboard panel binds to.
Aggregates matching events into fixed-width time buckets, producing one row per bucket, or per bucket and series when you add a by clause. This is the shape a dashboard chart or metric panel plots.
It takes the same aggregation functions as stats.
Also written as bucket, which behaves identically.
Syntax
| timechart [span=<duration>] [limit=<count>] <function>(<field>) [AS <name>] [, ...] [by <field> [, <field> ...]]Square brackets mark an optional part, and angle brackets a value you supply.
Arguments
| Argument | Required | Description |
|---|---|---|
span=<duration> | Optional | The width of each bucket: a whole number and a unit, such as 30s, 5m, 1h or 1d. Units are ms, s, m, h, d and w. Leave it off, or write span=auto, to size the buckets from the time range: about sixty buckets, rounded up to a familiar width. The default one-hour range gives one-minute buckets. |
limit=<count> | Optional | How many series a chart plots, ranked by size. limit=0 plots every series. This only affects how the chart is drawn. To cap result rows, use | limit. |
<function>(<field>) | Required | One or more aggregations from the list below, separated by commas. |
by <field>, ... | Optional | Splits each bucket into one series per value of the field, such as one line per service. |
Aggregation functions
| Function | Returns | Summary |
|---|---|---|
count | number | Number of matching events in each group. |
sum | number | Total of a numeric field. |
avg | number | Mean of a numeric field. |
min | number | Smallest value of a field. |
max | number | Largest value of a field. |
latest | number | Most recent numeric value of a field. |
p50 | number | Median (50th percentile) of a numeric field. |
p95 | number | 95th percentile of a numeric field. |
p99 | number | 99th percentile of a numeric field. |
distinct_count | number | Number of distinct values of a field. |
values | text | The distinct values of a field, sorted. |
count()
Counts the events, or rows, in each group. It takes no field: to count the different values a field holds, use distinct_count(field).
Returns: number
| stats count() by servicesum(<field>)
Adds up a numeric field across each group. Values that are not numbers are skipped rather than counted as zero.
Returns: number
| stats sum(bytes) AS total_bytes by hostavg(<field>)
The arithmetic mean of a numeric field across each group, ignoring events that do not carry a number for it.
Returns: number
| stats avg(duration_ms) by routemin(<field>)
The smallest value of a numeric field in each group. On the timestamp it gives the earliest event's time.
Returns: number
| stats min(duration_ms) by servicemax(<field>)
The largest value of a numeric field in each group. On the timestamp it gives the newest event's time.
Returns: number
| stats max(memory_used_mb) by hostlatest(<field>)
The field's numeric value on the newest event that carries one. Use it for a gauge, such as queue depth or free disk, where the current reading matters more than the peak.
Returns: number
| stats latest(queue_depth) by queuep50(<field>)
The median: half the values in each group are at or below it. Less affected by a few extreme values than avg(). Percentiles are calculated as close estimates.
Returns: number
| stats p50(duration_ms) by routep95(<field>)
The value 95% of the group is at or below. The usual measure of what a slow but not unusual request looks like.
Returns: number
| stats p95(duration_ms) by routep99(<field>)
The value 99% of the group is at or below. Shows the tail latency a small share of requests still sees.
Returns: number
| stats p99(duration_ms) by servicedistinct_count(<field>)
How many different values a field takes in each group, such as the number of users or hosts affected. The count is a close estimate on very large groups.
Returns: number
| stats distinct_count(user_id) AS users by countryvalues(<field>)
The group's distinct values of a field as one comma-separated piece of text, deduplicated and sorted, up to 100 values per group. Events without the field are skipped. The only aggregation that returns text rather than a number.
Returns: text
| stats values(host) by serviceUsage
bucketis another name fortimechartand behaves identically.- timechart does not work after inputlookup, because a table's rows have no timestamps.
- extract and json must come before timechart.
Examples
1. Event volume over time, per service
| timechart span=5m count() by serviceOne series per service, counted in five-minute buckets.
2. Latency trend with automatic buckets
service=checkout-api | timechart p95(duration_ms)The bucket width follows the selected time range, so zooming into a chart gives finer buckets.
3. Only the busiest series
level="error" | timechart span=1h limit=5 count() by servicePlots the five services with the most errors.
4. Alert on a per-bucket threshold
level="error" | timechart span=1m count() > 100Returns the one-minute buckets with more than 100 errors.