Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grafana: custom legend values?

Does anybody knows if it's possible to define custom legend values in Grafana?

From the documentation, there are a few possible functions:

Legend Values
Additional values can be shown along-side the legend names:

Total - Sum of all values returned from metric query
Current - Last value returned from the metric query
Min - Minimum of all values returned from metric query
Max - Maximum of all values returned from the metric query
Avg - Average of all values returned from metric query
Decimals - Controls how many decimals are displayed for legend values (and graph hover tooltips)

The legend values are calculated client side by Grafana and depend on what type of aggregation or point consolidation you metric query is using.

What if I want to add another computation, such as a percentile or moving average?

If not possible, what are the solutions out there? The backend I'd like to use is Oracle.

Thanks

like image 673
Carmellose Avatar asked Mar 30 '17 13:03

Carmellose


1 Answers

That seems like an old question, so I am unsure which grafana version it was about. I don't think, however, that this functionality had changed between March 2017 and now (August 2018). Documentation link and description quoted in the question is about additional legend values, when the question is about custom legend values.

Grafana has a fixed, predefined set of additional legend values, as described in the documentation and the quote: Total, Current, Min, Max, Avg. The last one (Decimals) is not a value, it's a setting of how many decimals to display. So additional legend values could be only enabled/disabled from is set on the standard grafana graph panel reference in the question. Grafana has many 3rd party graph plugins and I can't be sure 100% but of the top of my head I don't know any custom plot which have customizable additional legend values.

That said, nothing, prevents you from having percentage or moving average as your metric. You can name it appropriately in the metric description and it'll appear as "Moving average" or "SMA" or "Percentage" or whatever you will call it. So, technically, you can have any of a wide range of available processing functions applied to your value as your metric and assign it a corresponding meaningful alias by which will be displayed in the legend (percentage or moving average, etc). Additional values on top of the metric might not make much sense (say an average of moving average or total of percentage is not very meaningful, but that could still be displayed).

It's especially convenient, while using InfluxDB as grafana provides nice metrics editor (notice alias by where you can use both plain text, tags and column names):

enter image description here

From what I see in oracle data-source plug-in, it looks like custom values can be made using SQL, as in this example MIN is used as a metric name to display in the legend:

SELECT
  $__timeGroup(time_date_time, '5m') AS time,
  MIN(value_double),
  'MIN' as metric
FROM test_data
WHERE $__timeFilter(time_date_time)
GROUP BY $__timeGroup(time_date_time, '5m')
ORDER BY time

So seems like it's possible to do percentile or moving average, etc. Unfortunately I have no oracle installation to try.

like image 85
isp-zax Avatar answered Sep 22 '22 05:09

isp-zax