Skip to main content
Track state transitions and system liveness over time. These functions help you analyze systems that switch between discrete states, monitor heartbeat signals for liveness detection, and calculate durations spent in different states. TimescaleDB Toolkit provides three approaches to state tracking:
  • compact_state_agg: Track time spent in each state with minimal memory usage
  • state_agg: Track state transitions with full timestamp information
  • heartbeat_agg: Monitor system liveness based on heartbeat signals

Two-step aggregation

This group of functions uses the two-step aggregation pattern. Rather than calculating the final result in one step, you first create an intermediate aggregate by using the aggregate function. Then, use any of the accessors on the intermediate aggregate to calculate a final result. You can also roll up multiple intermediate aggregates with the rollup functions. The two-step aggregation pattern has several advantages:
  1. More efficient because multiple accessors can reuse the same aggregate
  2. Easier to reason about performance, because aggregation is separate from final computation
  3. Easier to understand when calculations can be rolled up into larger intervals, especially in window functions and continuous aggregates
  4. Perform retrospective analysis even when underlying data is dropped, because the intermediate aggregate stores extra information not available in the final result
To learn more, see the blog post on two-step aggregates.

Samples

Track time in different states

Use compact_state_agg to efficiently track how much time a system spends in each state:
Query the duration spent in each state:

Analyze state transitions

Use state_agg to track when state transitions occur:

Monitor system liveness

Use heartbeat_agg to track uptime and downtime:

Available functions

Compact state aggregation

State aggregation with transitions

  • state_agg(): track state transitions with full timestamp information

Heartbeat monitoring