Browse docs
On this page

timechart command

Aggregate into fixed time buckets. The shape a dashboard panel binds to.

All ObiQL commands

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

ObiQL
| 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

ArgumentRequiredDescription
span=<duration>OptionalThe 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>OptionalHow 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>)RequiredOne or more aggregations from the list below, separated by commas.
by <field>, ...OptionalSplits each bucket into one series per value of the field, such as one line per service.

Aggregation functions

FunctionReturnsSummary
countnumberNumber of matching events in each group.
sumnumberTotal of a numeric field.
avgnumberMean of a numeric field.
minnumberSmallest value of a field.
maxnumberLargest value of a field.
latestnumberMost recent numeric value of a field.
p50numberMedian (50th percentile) of a numeric field.
p95number95th percentile of a numeric field.
p99number99th percentile of a numeric field.
distinct_countnumberNumber of distinct values of a field.
valuestextThe 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

ObiQL
| stats count() by service

sum(<field>)

Adds up a numeric field across each group. Values that are not numbers are skipped rather than counted as zero.

Returns: number

ObiQL
| stats sum(bytes) AS total_bytes by host

avg(<field>)

The arithmetic mean of a numeric field across each group, ignoring events that do not carry a number for it.

Returns: number

ObiQL
| stats avg(duration_ms) by route

min(<field>)

The smallest value of a numeric field in each group. On the timestamp it gives the earliest event's time.

Returns: number

ObiQL
| stats min(duration_ms) by service

max(<field>)

The largest value of a numeric field in each group. On the timestamp it gives the newest event's time.

Returns: number

ObiQL
| stats max(memory_used_mb) by host

latest(<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

ObiQL
| stats latest(queue_depth) by queue

p50(<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

ObiQL
| stats p50(duration_ms) by route

p95(<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

ObiQL
| stats p95(duration_ms) by route

p99(<field>)

The value 99% of the group is at or below. Shows the tail latency a small share of requests still sees.

Returns: number

ObiQL
| stats p99(duration_ms) by service

distinct_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

ObiQL
| stats distinct_count(user_id) AS users by country

values(<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

ObiQL
| stats values(host) by service

Usage

  • bucket is another name for timechart and 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

ObiQL
| timechart span=5m count() by service

One series per service, counted in five-minute buckets.

2. Latency trend with automatic buckets

ObiQL
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

ObiQL
level="error" | timechart span=1h limit=5 count() by service

Plots the five services with the most errors.

4. Alert on a per-bucket threshold

ObiQL
level="error" | timechart span=1m count() > 100

Returns the one-minute buckets with more than 100 errors.