How to do Mathematical calculation on grok filter output

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.

You can do your calculations with Ruby:
https://www.elastic.co/guide/en/logstash/current/event-api.html#_ruby_filter

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

or can install: https://github.com/logstash-plugins/logstash-filter-math

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