# How to do Mathematical calculation on grok filter output

**URL:** <https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063>\
**Category:** Logstash\
**Created:** [August 6, 2020, 4:25pm UTC](https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063 "2020-08-06T16:25:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabhc](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@saurabhc](https://discuss.elastic.co/u/saurabhc)\
**Post date:** [August 6, 2020, 4:25pm UTC](https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063/1 "2020-08-06T16:25:21Z")

</div>

My Input file looks like below.

```
MemoryTotal: 100831888 kB
MemoryFree: 1212388 kB
MemoryAvailable: 49997588 kB

```

I am filtering the values like "MemFree:\s+%{NUMBER:mem\_free}","MemTotal:\s+%{NUMBER:mem\_total}", "MemAvailable:\s+%{NUMBER:mem\_available}".  
Now the output _mem\_free_, _mem\_total_, _mem\_available_ value I'm getting is in **kB** , but I want that converted to **MB** in logstash output only i.e. the output value should be _mem\_free_, _mem\_total_, _mem\_available_ values divided by 1024.  
How I can achieve that.

Apologies, similar question might have been asked previously, but I couldn't get the answer.

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [August 6, 2020, 5:51pm UTC](https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063/2 "2020-08-06T17:51:38Z")

</div>

You can do your calculations with Ruby:  
[https://www.elastic.co/guide/en/logstash/current/event-api.html#\_ruby\_filter](https://www.elastic.co/guide/en/logstash/current/event-api.html#_ruby_filter)

---

<div class="post-metadata">

**Author:** ![kelk](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelk](https://discuss.elastic.co/u/kelk)\
**Post date:** [August 6, 2020, 5:52pm UTC](https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063/3 "2020-08-06T17:52:55Z")

</div>

if this is ONLY for bytes/kB etc, you can use [https://www.elastic.co/guide/en/logstash/current/plugins-filters-bytes.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-bytes.html)

or can install: [https://github.com/logstash-plugins/logstash-filter-math](https://github.com/logstash-plugins/logstash-filter-math)

---

<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:** [September 3, 2020, 5:53pm UTC](https://discuss.elastic.co/t/how-to-do-mathematical-calculation-on-grok-filter-output/244063/4 "2020-09-03T17:53:05Z")

</div>

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