# Find Ratio Between Two Metrics

**URL:** <https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153>\
**Category:** Kibana\
**Created:** [June 8, 2016, 6:11am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153 "2016-06-08T06:11:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oferkes](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oferkes](https://discuss.elastic.co/u/Oferkes)\
**Post date:** [June 8, 2016, 6:11am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/1 "2016-06-08T06:11:34Z")

</div>

Hi,

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?

Thanks,  
Ofer

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [June 8, 2016, 7:42pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/2 "2016-06-08T19:42:11Z")

</div>

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: [https://github.com/elastic/kibana/issues/4584](https://github.com/elastic/kibana/issues/4584)

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

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 8, 2016, 11:56pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/3 "2016-06-08T23:56:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Oferkes](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oferkes](https://discuss.elastic.co/u/Oferkes)\
**Post date:** [June 9, 2016, 4:02am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/4 "2016-06-09T04:02:01Z")

</div>

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.

thanks!

---

<div class="post-metadata">

**Author:** ![Oferkes](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oferkes](https://discuss.elastic.co/u/Oferkes)\
**Post date:** [June 9, 2016, 4:04am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/5 "2016-06-09T04:04:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Oferkes](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oferkes](https://discuss.elastic.co/u/Oferkes)\
**Post date:** [June 10, 2016, 7:58am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/6 "2016-06-10T07:58:44Z")

</div>

Hi all,

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

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 11, 2016, 5:34pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/7 "2016-06-11T17:34:44Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![Oferkes](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oferkes](https://discuss.elastic.co/u/Oferkes)\
**Post date:** [June 11, 2016, 5:47pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/8 "2016-06-11T17:47:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 12, 2016, 8:53am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/9 "2016-06-12T08:53:18Z")

</div>

Yeah, I misread that one ☹

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [July 11, 2016, 8:13am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/10 "2016-07-11T08:13:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 11, 2016, 10:50am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/11 "2016-07-11T10:50:34Z")

</div>

Not at this point in time.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [July 12, 2016, 8:25am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/12 "2016-07-12T08:25:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 12, 2016, 8:28am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/13 "2016-07-12T08:28:21Z")

</div>

You'd have to take a look in github.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [July 20, 2016, 8:59am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/14 "2016-07-20T08:59:44Z")

</div>

Hi @warkolm I found this [https://github.com/elastic/kibana/pull/5558#issuecomment-231696586](https://github.com/elastic/kibana/pull/5558#issuecomment-231696586) but it seems Kibana don't have any planned work on adding this feature. I wish I knew this when I first considered Kibana ☹ I'll start my search for a replacement.

---

<div class="post-metadata">

**Author:** ![JuanCarniglia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juancarniglia/32/11154_2.png) [@JuanCarniglia](https://discuss.elastic.co/u/JuanCarniglia)\
**Post date:** [August 2, 2016, 3:18am UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/15 "2016-08-02T03:18:24Z")

</div>

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 %).

![](https://us1.discourse-cdn.com/elastic/original/2X/9/96a936881a397f31cbe8c225e7eedce20fc55c9b.png)

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 [https://github.com/JuanCarniglia](https://github.com/JuanCarniglia).

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [August 31, 2016, 1:05pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/16 "2016-08-31T13:05:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JuanCarniglia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juancarniglia/32/11154_2.png) [@JuanCarniglia](https://discuss.elastic.co/u/JuanCarniglia)\
**Post date:** [August 31, 2016, 2:17pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/17 "2016-08-31T14:17:44Z")

</div>

You could. Have you tried TimeLion?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [August 31, 2016, 2:19pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/18 "2016-08-31T14:19:11Z")

</div>

TimeLion doesn't provide metrics. Only a graph.

---

<div class="post-metadata">

**Author:** ![JuanCarniglia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juancarniglia/32/11154_2.png) [@JuanCarniglia](https://discuss.elastic.co/u/JuanCarniglia)\
**Post date:** [August 31, 2016, 2:25pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/19 "2016-08-31T14:25:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [August 31, 2016, 2:25pm UTC](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153/20 "2016-08-31T14:25:48Z")

</div>

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

[Next page](https://discuss.elastic.co/t/find-ratio-between-two-metrics/52153.md?page=2)
