# Smoothing

## Autosmooth

Function Description Example
`autosmooth()` Automatically removes noise while preserving the trend of the metric. `autosmooth(<METRIC_NAME>{*})`

The `autosmooth()` function applies a moving average with an automatically selected span. It smooths a timeseries while preserving its trend. In this example, the function chooses the optimal span to smooth the timeseries:

When used on a `group by` query (e.g. `avg by`), the same span is applied on all the timeseries. If used on several metrics in the same graph, different spans can be selected to optimally smooth each one of the metric timeseries.

The algorithm is inspired by the ASAP algorithm-you can read more about it in this blog post.

The `autosmooth()` function cannot be used in monitors. Being that the span is chosen dynamically, the result of applying the function could change from minute to minute, making threshold setting difficult and leading to alert flapping.

## Exponentially weighted moving average

### Ewma 3

Function Description Example
`ewma_3()` Compute the exponentially weighted moving average over a span of 3. `ewma_3(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `ewma_3()` uses the last 3 data points to calculate the average.

Example:

If we have a metric `10 + x%10 {*}` that just increments itself by 1 starting from 10 until it drops back to 10 after 10 data points, then `ewma3(10 + x%10 {*})` has the following shape:

### Ewma 5

Function Description Example
`ewma_5()` Compute the exponentially weighted moving average over a span of 5. `ewma_5(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `ewma_5()` uses the last 5 data points to calculate the average.

Example:

If we have a metric `10 + x%10 {*}` that just increments itself by 1 starting from 10 until it drops back to 10 after 10 data points, then `ewma5(10 + x%10 {*})` has the following shape:

### Ewma 10

Function Description Example
`ewma_10()` Compute the exponentially weighted moving average over a span of 10. `ewma_10(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `ewma_10()` uses the last 10 data points to calculate the average.

Example:

If we have a metric `10 + x%10 {*}` that just increments itself by 1 starting from 10 until it drops back to 10 after 10 data points, then `ewma10(10 + x%10 {*})` has the following shape:

### Ewma 20

Function Description Example
`ewma_20()` Compute the exponentially weighted moving average over a span of 20. `ewma_20(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `ewma_20()` uses the last 20 data points to calculate the average.

Example:

If we have a metric `10 + x%10 {*}` that just increments itself by 1 starting from 10 until it drops back to 10 after 10 data points, then `ewma20(10 + x%10 {*})` has the following shape:

## Median

### Median 3

Function Description Example
`median_3()` Rolling median with a span of 3. `median_3(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `median_3()` uses the last 3 data points to calculate the median.

### Median 5

Function Description Example
`median_5()` Rolling median with a span of 5. `median_5(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `median_5()` uses the last 5 data points to calculate the median.

### Median 7

Function Description Example
`median_7()` Rolling median with a span of 7. `median_7(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `median_7()` uses the last 7 data points to calculate the median.

### Median 9

Function Description Example
`median_9()` Rolling median with a span of 9. `median_3(<METRIC_NAME>{*})`

Note: The span value is the number of data points. So `median_9()` uses the last 9 data points to calculate the median.

## Other functions

Consult the other available functions: