Skip to content

Counts, facets and histograms

Count matching events, list the most frequent services and hosts, and bucket events over time.

Updated

Counts, facets and histograms summarize every matching event in a time window. They accept the same filters as search, including attribute filters.

Each request reads the data at its own point in time, so two requests with identical bounds can disagree while ingestion or retention is running.

The examples assume $FROM, $TO, $LOGBROOK_URL and $LOGBROOK_READ_TOKEN from the search page, and an index named checkout.

Count

logbrook count checkout --since 1h
logbrook count checkout --since 1h --service api --min-level 50
logbrook count checkout --since 1h --min-level 50 --json

The output is a bare number, or { "count": 5 } with --json.

curl --fail-with-body --silent --show-error --get \
  "$LOGBROOK_URL/indexes/checkout/logs/count" \
  -H "Authorization: Bearer $LOGBROOK_READ_TOKEN" \
  --data-urlencode "from=$FROM" --data-urlencode "to=$TO" \
  --data-urlencode 'min_level=50'
{ "count": 5 }

A window with no matches returns { "count": 0 }.

Facets

Facets list the most frequent values of the built-in fields. They’re HTTP only: the CLI has no facets command.

curl --fail-with-body --silent --show-error --get \
  "$LOGBROOK_URL/indexes/checkout/logs/facets" \
  -H "Authorization: Bearer $LOGBROOK_READ_TOKEN" \
  --data-urlencode "from=$FROM" --data-urlencode "to=$TO" \
  --data-urlencode 'min_level=50' | jq '.services'

The response has five arrays: services, loggers, hosts, levels and sources. Each holds value and count pairs:

[
  { "value": "api", "count": 9 },
  { "value": "worker", "count": 2 },
  { "value": "auth", "count": 1 }
]
  • Each array holds at most 100 values, sorted by descending count.
  • Level values are strings, such as "50".
  • Events without an optional field are left out of that field’s array, so an array doesn’t always add up to the total.
  • Filters apply before grouping, including a filter on the field being grouped. With service=api, the services array shows only api.
  • You can’t group by a custom attribute.

Histograms

A histogram counts events in fixed-width time buckets. It’s HTTP only.

curl --fail-with-body --silent --show-error --get \
  "$LOGBROOK_URL/indexes/checkout/logs/histogram" \
  -H "Authorization: Bearer $LOGBROOK_READ_TOKEN" \
  --data-urlencode "from=$FROM" --data-urlencode "to=$TO" \
  --data-urlencode 'interval_ms=300000' \
  --data-urlencode 'min_level=50'
{ "buckets": [{ "time": 1791370000000, "count": 3 }] }
  • time is the bucket start in Unix milliseconds, counted from the exact from you sent.
  • Buckets come in ascending order.
  • Empty buckets are left out. Fill them with zeros when charting.
  • The last bucket can be shorter than the interval.
  • An empty histogram is { "buckets": [] }.

Bucket size and limit

interval_ms is a positive bucket width in milliseconds. A request can cover at most 2,000 buckets, counting a partial last bucket: ceil((to - from) / interval_ms) <= 2000. Over the limit, it returns 400.

Window Interval Buckets
1 hour 60000 (1 minute) 60
1 day 60000 1,440
7 days 60000 10,080, rejected
7 days 900000 (15 minutes) 672

Without interval_ms, the server uses 60,000 ms, or the smallest interval that fits 2,000 buckets if that is larger.

Only search accepts limit and cursor, and only histogram accepts interval_ms. Sending them to another endpoint returns 400.

Next steps

Type to search…

↑↓ navigate↵ selectEsc close