8
votes

I'm looking for a function in Grafana which looks like it should be trivial, but until now I haven't been able to find out how, if at all, it is possible to do.

With the recent templating options, I can easily create my dashboard once, and quickly change the displayed data to look at different subsets of my data, and that's great. What I'm looking for is a way to combine this functionality to create interactive graphs that show aggregations on different subsets of my data.

E.g., the relevant measurement for me is a "clicks per views" measurement. For each point in the series, I can calculate this ratio for each state (or node) in code before sending it to the graphite layer, and this is what I've been doing until now.

My problem starts where I want to combine several states together, interactively: I could use the "*" in one of the nodes, and use an aggregate function like "avg" or "sum" to collect the different values covered in the sub-nodes together.

Problem is, I can't just use an average of averages - as the numbers may be calculated on very different sample sizes,the results will be highly inaccurate.
Instead, I'd like to send to the graphite the "raw data" - number of clicks and number of views per state for each point in the series, and have grafana calculate something like "per specified states, aggregate number of clicks AND DIVIDE BY aggregate number of views".

Is there a was to do this? as far as I can tell, the asPercent function doesn't seem to do the trick.

1

1 Answers

0
votes

You can use a query like this in edit mode:

SELECT (aggregate_function1(number_of_clicks)/aggregate_function2(number_of_views)) as result 
FROM measurement_name 
WHERE $timeFilter 
GROUP BY time($_interval), state.