gauge_agg()

Produces a GaugeSummary that can be used to accumulate gauge data for further calculations.

2. gauge_agg (

4. ts TIMESTAMPTZ,

6. value DOUBLE PRECISION

8. ) RETURNS GaugeSummary
warning

Experimental features could have bugs. They might not be backwards compatible, and could be removed in future releases. Use these features at your own risk, and do not use any experimental features in production.

For more information about counter and gauge aggregation functions, see the hyperfunctions documentation.

Required arguments

Name Type Description
ts TIMESTAMPTZ The time at each point
value DOUBLE PRECISION The value at that timestamp

Only DOUBLE PRECISION values are accepted for the value parameter. For gauge data stored as other numeric types, cast it to DOUBLE PRECISION when using the function.

note

If there are NULL values in your data, the aggregate ignores them and aggregates only non-NULL values. If you only have NULL values, the aggregate returns NULL.

Optional arguments

Name Type Description
bounds TSTZRANGE The largest and smallest possible times that can be input to the aggregate. Calling with NULL, or leaving out the argument, results in an unbounded GaugeSummary
important

Bounds are required for extrapolation, but not for other accessor functions.

Returns

Column Type Description
gauge_agg GaugeSummary A GaugeSummary object that can be passed to accessor functions or other objects in the gauge aggregate API
important

The returned GaugeSummary can be used as an input the accessor functions delta, idelta_left, and idelta_right. When this feature is mature, it will support all the same accessor functions as CounterSummary, with the exception of num_resets.

Sample usage

Create a gauge summary from time-series data that has a timestamp, ts, and a gauge value, val. Get the instantaneous rate of change from the last 2 time intervals using the irate_right accessor:

2. WITH t as (

4. SELECT

6. time_bucket('1 day'::interval, ts) as dt,

8. gauge_agg(ts, val) AS gs

10. FROM foo

12. WHERE id = 'bar'

14. GROUP BY time_bucket('1 day'::interval, ts)

16. )

18. SELECT

20. dt,

22. irate_right(gs)

24. FROM t;