Skip to content

avg

Average or mean aggregation operator. There are two variants of the :avg operator.

Aggregation

Input Stack:
query: Query
Output Stack:
AggregationFunction

Compute the average (arithmetic mean) of all matching time series. This is a helper method that uses the count aggregate to determine how many time series have data at each interval and divides the sum of the values by the count. This avoids issues where some time series are missing data at specific times, which would result in an artificially low average.

Parameters

  • query: A query expression that selects the time series to aggregate

Examples

Find the average CPU usage across all matching nodes:

name,ssCpuUser,:eq,
:avg

when matching against the sample data in the table below, the highlighted time series would be included in the aggregate result:

Namenf.appnf.nodeData
ssCpuUser alerttest i-0123 [1.0, 2.0, NaN]
ssCpuSystem alerttest i-0123 [3.0, 4.0, 5.0]
ssCpuUser nccp i-0abc [8.0, 7.0, 6.0]
ssCpuSystem nccp i-0abc [6.0, 7.0, 8.0]
numRequests nccp i-0abc [1.0, 2.0, 4.0]
ssCpuUser api i-0456 [1.0, 2.0, 2.0]

The values from the corresponding intervals will be aggregated. For the first interval using the sample data above the values are 1.0, 8.0, and 1.0. The arithmetic mean of these non-NaN values is calculated (10.0/3 = 3.33). This leads to a final result of:

NameData
ssCpuUser [3.33, 3.66, 4.0]

The only tags for the aggregated result are those that are matched exactly (:eq clause) as part of the choosing criteria or are included in a group by.

Math

Input Stack:
expr: TimeSeriesExpr
Output Stack:
TimeSeriesExpr

Compute the average of all the time series from the input expression. This variant is typically used when you need to apply a different aggregation function for grouping first, then find the average across the groups.

Parameters

  • expr: A time series expression that may contain multiple series to average

Examples

First group by cluster using max aggregation, then find the average across all groups:

BeforeAfter
name,sps,:eq,
(,nf.cluster,),:by
name,sps,:eq,
:max,
(,nf.cluster,),:by,
:avg
  • :sum - Sum aggregation function
  • :max - Maximum aggregation function
  • :min - Minimum aggregation function
  • :count - Count aggregation function
  • :node-avg - Average normalized by instance count
  • :eureka-avg - Average using active instances in Eureka service discovery
  • :dist-avg - Average for timer/distribution metrics