gauge_agg()

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

  1. gauge_agg (
  2. ts TIMESTAMPTZ,
  3. value DOUBLE PRECISION
  4. ) 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

NameTypeDescription
tsTIMESTAMPTZThe time at each point
valueDOUBLE PRECISIONThe 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

NameTypeDescription
boundsTSTZRANGEThe 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

ColumnTypeDescription
gauge_aggGaugeSummaryA 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:

  1. WITH t as (
  2. SELECT
  3. time_bucket('1 day'::interval, ts) as dt,
  4. gauge_agg(ts, val) AS gs
  5. FROM foo
  6. WHERE id = 'bar'
  7. GROUP BY time_bucket('1 day'::interval, ts)
  8. )
  9. SELECT
  10. dt,
  11. irate_right(gs)
  12. FROM t;