Hi. I am struggling to get the duration for a start and end date in a log entry. I have the following fields:
TIME=2016/05/29 13:23:04.286
TIME_END=2016/05/29 13:23:04.493
I would like to get the duration between the two fields, I have tried the following however it is not working:
mutate {
add_field => { elapsed => "%{TIME}-%{TIME_END}" }
}
and this code, however also did not work:
ruby {
code => "event['duration'] = (event['TIME']) - map['TIME_END']"
}
Any suggestions on how to get the duration between the two fields would be appreciated.
Here is my code that I am using:
input {
file {
type => "probe"
path => [ "/Syslogs/_files/*.TXT" ]
start_position => beginning
sincedb_path => "/Syslogs/db/probe"
ignore_older => 864000000000
}
}
in my log I have action start time and action end time formatted as HHmmss.
I used the following code in my logstash filter.
It works well if the action lasts during the same day.
However, I run into problems when the action end time passes midnight.
For example: this action's duration is 5 minutes
action start time 23:58:00
action end time 00:03:00 the next day
Then I get a wrong calculation (negative value).
I appreciate any help in solving this problem.
# get the duration of the action_time
date {
match => ["[action_start_time]", "HHmmss"]
target => "[action_start_timed]"
timezone => "America/New_York"
}
date {
match => ["[action_end_time]", "HHmmss"]
target => "[action_end_timed]"
timezone => "America/New_York"
}
ruby {
code => "event['action_duration'] = (event['action_end_timed'] - event['action_start_timed'])"
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.