# Unable to use if condition and calculate percenatge inside ruby code

**URL:** <https://discuss.elastic.co/t/unable-to-use-if-condition-and-calculate-percenatge-inside-ruby-code/167586>\
**Category:** Logstash\
**Created:** [February 8, 2019, 8:38am UTC](https://discuss.elastic.co/t/unable-to-use-if-condition-and-calculate-percenatge-inside-ruby-code/167586 "2019-02-08T08:38:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sapna](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@Sapna](https://discuss.elastic.co/u/Sapna)\
**Post date:** [February 8, 2019, 8:38am UTC](https://discuss.elastic.co/t/unable-to-use-if-condition-and-calculate-percenatge-inside-ruby-code/167586/1 "2019-02-08T08:38:11Z")

</div>

Hello,  
I am trying to first filter my data with only 3 KPI and only with hostname which domain is ".xxx.com".  
then I want to calculate percentage from value\_current and value\_max columns.  
filter{  
mutate {convert =\> ["value\_current", "integer"]}  
mutate {convert =\> ["value\_max", "integer"]}  
if [kpi\_name] in ["DiskFilesystemUtilization","CpuUtilization","MemoryUtilization"]{  
if ("[xxxx.com](http://xxxx.com)" in [host\_name]){

```
                    ruby{
                                                          
                                    code => 'event.set("[Percentage]",[event.get("[value_current]") / event.get("[value_max]") * 100 ] )'
                            }
                        }

```

}  
}

This does not look at filter and sending the data as it is.

It works only if I put if condition in output section of logstash. but that takes lot of time to first calculate percentage and then filter with 3 KPI and host names.

---

<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:** [March 8, 2019, 8:38am UTC](https://discuss.elastic.co/t/unable-to-use-if-condition-and-calculate-percenatge-inside-ruby-code/167586/2 "2019-03-08T08:38:25Z")

</div>

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