Conditionally count logs before and after 1 hour ago
Problem / Use case
You want to compare how many logs occurred in the last hour versus earlier. This helps validate time-based patterns, throttling, or backlogs.
Query
Expected output
| _expr0 | _count |
|---|---|
| older | 256305608 |
| last_hour | 31830 |
Note
If your timestamp is stored as a string in ISO 8601 format, cast it to a proper timestamp using timestamp:timestamp before performing time arithmetic.
Variations
- Swap
1hfor30m,6h, or1dto shift the time cutoff. - Replace
timestampwith any timestamp-related field likeevent_time,created_at, etc.
TL;DR
Use if(timestamp > now() - 1h, ...) inside countby to bucket logs into time-based groups. Perfect for detecting bursts or delays.
Theme
Light