Find Ratio Between Two Metrics


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?



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

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

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.


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?

Hi all,

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

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?

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.

Yeah, I misread that one :frowning:

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

Not at this point in time.

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?

You'd have to take a look in github.

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.

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

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

You could. Have you tried TimeLion?

TimeLion doesn't provide metrics. Only a graph.

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.

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