Find Ratio Between Two Metrics

(Ofer Kesten) #1


i have 2 metrics that i calculate in Kibana:

  1. sum of disk usage
  2. sum of disk size

What i would like to get is:
(sum of disk usage) / (sum of disk size).
This seem to be fairly basic requirement but i cant figure out how to do it in Kibana.
Is there any way of doing so?


(Tim Sullivan) #2

If you want to do a calculation against the results of aggregations, you need pipeline aggregations, which unfortunately are not supported in Kibana yet. You can track the progress of that implementation here:

You have a couple options before pipeline aggregations are implemented in Kibana.

  • You can run the pipeline query in a script and index the result as an ordinary series that Kibana can read, then graph that
  • You can experiment with the Timelion plugin if your data is time-based and use the functions it provides. I think that would only work if your data is a time-series though. Full disclosure, I don't have a lot of experience with Timelion

(Mark Walkom) #3

You can create a scripted field that does this as well.

(Ofer Kesten) #4

Hi Tim,

thanks for the reply, i will look into the pipeline aggregation, and definitely follow the status of the implementation as i think this is a very required feature.


(Ofer Kesten) #5

Hi warkolm,

i thought about doing so with scripted field, and created a scripted field with the following script for each document:
doc['SizeTB'].value > 0 ? (doc['UsageTB'].value/doc['SizeTB'].value) : 0
this provides the required data for a single document, but when aggregating them all together, it is mathematically wrong, and gives the wrong numbers.
Did you have something else in mind?

(Ofer Kesten) #6

Hi all,

Does anyone have an idea on how to workaround this?
All i need is a metric that shows sum(a)/sum(b)..

(Magnus Bäck) #7

You can create a scripted field that does this as well.

Really? You can certainly create a scripted field that calculates the ratio in question for each document, but how would you meaningfully aggregate that?

(Ofer Kesten) #8

This is the problem. Scripted field wont help here as it will be correct per document, but will lose its meaning once all documents will be aggregated.

(Mark Walkom) #9

Yeah, I misread that one :frowning:

(Jeremy Colton) #10

So excluding TimeLion, a metric showing a ratio is not possible?

(Mark Walkom) #11

Not at this point in time.

(Jeremy Colton) #12

This is a very basic need for most dashboards and my company is considering dumping Kibana because of this :frowning: Is this feature on the Kibana roadmap for the near future?

(Mark Walkom) #13

You'd have to take a look in github.

(Jeremy Colton) #14

Hi @warkolm I found this but it seems Kibana don't have any planned work on adding this feature. I wish I knew this when I first considered Kibana :frowning: I'll start my search for a replacement.

(Juan Ignacio Carniglia) #15

Jeremy, I just read this post.

I have deloped custom visualizations, and one of those (kbn_percent_nice_vis) actually takes a Metric (Count) and divides this count by an Aggregated field (for instance a Filter) count.

It then rounds up the value into 0-100, 10 by 10 intervals in order to show an image (a different image for each %).

Anyway, it's a couple of lines of code away from what you are requesting.

If you are still interested, we can discuss this.

Check out my Kibana work at

(Jeremy Colton) #16

hey @JuanCarniglia, thanks for your reply. I don't need percents or images, just the metric. Can I use your visual for this?

many thanks

(Juan Ignacio Carniglia) #17

You could. Have you tried TimeLion?

(Jeremy Colton) #18

TimeLion doesn't provide metrics. Only a graph.

(Juan Ignacio Carniglia) #19

What would you do with such result? Display it as a single number? On a table? Plot it?

When you use a custom visualization, you develop that visualization for a single usage.

(Jeremy Colton) #20

Display it as a single number, just like other metrics.