Need a math functions in logstash
Description
Gliffy Diagrams
Activity
Aaron Mildenstein February 6, 2015 at 9:23 PM
These math functions are available through the ruby filter, as outlined in the comments.
Damien Gouyette May 6, 2014 at 6:42 AM
You can take a look at this pull request i made.
It provide basic maths operations + - / *
https://github.com/dgouyette/logstash/commit/edfa976595355b7270fb1ac1650342ad364eb0a3
Matheus Cunha December 4, 2013 at 2:26 PM
Sagi,
Your idea was right, so I only had to do a little adjust.
{code => "event['test'] = event['reqsecs'].to_f * 1000000"}
Thank you,
Crazy Horse December 3, 2013 at 1:57 PM
Matheus,
This is probably because "reqsecs" field is set as string and not integer. Try this one:
ruby
{ code => "event['test'] = Integer(event['reqsecs']) * 1000000" }
and if this doesn't work:
ruby
{ code => "event['test'] = String(Integer(event['reqsecs']) * 1000000)" }
Basically Integer() converts a string to an integer (AFAIK, overflow is not an issue since ruby's integers are implemented in software).
String() converts everything to string.
Matheus Cunha December 3, 2013 at 1:17 PMEdited
Hi,
thank you for your help.
ruby {
code => "event['test'] = event['reqsecs'] * 1000000"
}
I tried the above code, but the result was reqsecs repeated one million times.
i.e.
I have custom fields 'hours','minutes','seconds' and I want to create on field 'seconds' = hours * 3600 + minutes * 60 + seconds.