# Calculate Percentage of utilization

**URL:** <https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689>\
**Category:** Kibana\
**Created:** [September 8, 2021, 3:11pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689 "2021-09-08T15:11:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 8, 2021, 3:11pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/1 "2021-09-08T15:11:54Z")

</div>

Hello,  
I am wanting to make a Kibana visualization that will give me the percentage of time that a task is running. I have a field called totalExecuationTimeInSeconds, that I would like to divide into the amount of time shown in the selected timespan in seconds. I would assume that it would look something like totalExecutionTimeInSeconds/timespan.ToSeconds  
Thanks for your thoughts/Suggestions

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [September 14, 2021, 12:54pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/2 "2021-09-14T12:54:14Z")

</div>

Hello @mericaforrestgumpsun

> amount of time shown in the selected timespan in seconds

Is that a value in an ES document?

What version fo the elastic stack are you using?

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 14, 2021, 1:05pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/3 "2021-09-14T13:05:56Z")

</div>

# 7.10.2 is the elastic version

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 14, 2021, 1:06pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/4 "2021-09-14T13:06:30Z")

</div>

How would I view the values in an ES document?

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [September 14, 2021, 2:46pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/5 "2021-09-14T14:46:59Z")

</div>

@mericaforrestgumpsun

Discover (in Kibana) would be my first recommendation.

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 14, 2021, 2:57pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/6 "2021-09-14T14:57:28Z")

</div>

Yea the value is a int that represents the amount of time a process takes

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [September 14, 2021, 3:05pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/7 "2021-09-14T15:05:31Z")

</div>

Scripted fields can be used to perform calculations. They're deprecated in newer version of kibana in favor of runtime fields. Runtime fields are very similar and have some advantages.

I understand that you have the numerator you need, but its unclear to me if you'll have access to the denominator. If its in a document or otherwise the result of an aggregation then yes. If you want access to the time range selected in search bar then the answer is no. Perhaps we should put in a request for this.

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 14, 2021, 3:26pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/8 "2021-09-14T15:26:15Z")

</div>

alright thanks for your insight

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 14, 2021, 3:32pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/9 "2021-09-14T15:32:17Z")

</div>

I found that I can actually find the denominator for this equasion or find the selected duration like so ((last(params.\_all.TransactionExecutionTime.timestamps) - first(params.\_all.TransactionExecutionTime.timestamps)) /1000). Because The timestamps are stored in unix standard format if you take the last element of the timestamps array and subtract it from the first that will give you the amount of time selected in milliseconds, so if you divide it by 1000 that will give you the time selected in seconds

---

<div class="post-metadata">

**Author:** ![mericaforrestgumpsun](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mericaforrestgumpsun](https://discuss.elastic.co/u/mericaforrestgumpsun)\
**Post date:** [September 20, 2021, 6:25pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/10 "2021-09-20T18:25:28Z")

</div>

Upon further inspection I found that for some reason the tsvb visualization I am using is not always filling the numerator in this operation, which I found unusual since the metric visualization seemed to work with the same logic for accounting for the value.

That logic being Aggregation Sum of Field totalExecuationTimeInSeconds.  
When is set the timespan to a week the metric visualization shows around 11k where as the TSVB visualization is showing either around 1k or zero. I am unsure as to how to account for this and any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 18, 2021, 6:25pm UTC](https://discuss.elastic.co/t/calculate-percentage-of-utilization/283689/11 "2021-10-18T18:25:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
