Is There A Way To Have A Moving Average In Grafana?


Answer :

Grafana supports adding a movingAverage(). I also had a hard time finding it in the docs, but you can (somewhat hilariously) see its usage on the feature intro page:

screenshot showing movingAverage() call

As is normal, click on the graph title, edit, add the metric movingAverage() as per described in the graphite documentation:

movingAverage(seriesList, windowSize)

Graphs the moving average of a metric (or metrics) over a fixed number of past points, or a time interval.

Takes one metric or a wildcard seriesList followed by a number N of datapoints or a quoted string with a length of time like ‘1hour’ or ‘5min’ (See from / until in the render_api_ for examples of time formats). Graphs the average of the preceding datapoints for each point on the graph. All previous datapoints are set to None at the beginning of the graph.

Example:

&target=movingAverage(Server.instance01.threads.busy,10)&target=movingAverage(Server.instance*.threads.idle,'5min')

Grafana does no calculations itself, it just queries a backend and draws nice charts. So aggregating abilities depends solely on your backend. While Graphite supports windowing functions such as moving average, InfluxDB currently doesn't support it.

There are quite a lot requests for moving average in influxdb on the web. You can leave your "+1" and track progress in this ticket https://github.com/influxdb/influxdb/issues/77

Possible (yet not so easy) workaround is to create a custom script (cron, daemon, whatever) that will pre-calcuate MA and save it in a separate influxdb series.


I found myself here trying to do a moving average in Grafana with a PostgreSQL database, so I'll just add a way to do with a SQL query:

SELECT  date as time,  AVG(daily_average_column)     OVER(ORDER BY date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW)     AS value,  '5 Day Moving Average' as metricFROM daily_average_tableORDER BY time ASC;

This uses a "window" function to average of the last 4 rows (plus the current row).

I'm sure there are ways to do this with MySQL as well.


Belum ada Komentar untuk "Is There A Way To Have A Moving Average In Grafana?"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel