moving_average(set[], options={})

This is an alias to window, with the function parameter set to mean. The options map accepts the following:

  • size - The size of the window to average over, see documentation for window.

Example:

The following expression plots the moving average of the metric api.auth.time.p99 over a window size of 5.

moving_average(
    max(s("api.auth.time.p99",{"host": "prod.web*"},{function:"max"})), {size:"5"})

The resulting chart demonstrates how the moving_average function will rise with any spikes in the bare metric, but smooth out lesser noise. The chart includes the bare metric api.auth.time.p99 for comparison, which displays many spikes not seen in the composite metric.

moving-average-example

Note: Composite metrics that you set up for alerting and that use window() or moving_average() functions use a start time of the query 15 minutes in the past, effectively allowing a maximum window size of 15 minutes for the query.