How to sum values from query into a singlestat or other plugin?

Is it possible to make a sum of values - depending on multi-selections in query (templating) - and showing those in a singlestat plugin in grafana?

setup:

  • grafana 3.1.1
  • datatsource: graphite

Use case:

A query-based dropdownlist allows me to select a logical volume.

The singlestat then shows me the size of this logical volume.

Now I have a multi-select query list so I’d love to achieve that the size value for each of those selected logical volumes is summed and shown in the singlestat.

I’ve been trying to find some function and I know there are sum functions but in my case, I don’t know which are going to be the results of the selections in the templating query and there doesn’t seem to exist a way to automatically add an “invisible” query to the metrics section while only showing a sum-of-all-queries-metric.

Are there any options to achieve this?

a sample query:

collectd.$host.$volumegroups.$logicalvolumes

where all 3 values are from a templating query with results like:

$host => the server in question
$volumegroups => vg00 (LVM Volume Group)
$logicalvolumes => lv_data, lv_root, ... (LVM Logical Volume)

Now when selecting multiple “$logicalvolumes” from the dropdown ofcourse, the singlestat goes “N/A”.

In the list of plugins on grafana website, I don’t find any other plugin to match this need.

Wrapping the query in a sumSeries() should do what you want, i.e. sumSeries(collectd.$host.$volumegroups.$logicalvolumes).

2 Likes