I am using the latest version of logstash(7.6.2). I am trying to calculate the total time spent in system excluding time spent between Out2 and In2 i.e. [(Out3-In1) - (Out2-In2)] for a given ID. Find below my sample data with columns Timestamp, Event, and ID
Sample Data
18/May/2015:02:05:10 +0000 In1 100
18/May/2015:02:05:15 +0000 Out1 100
18/May/2015:02:05:26 +0000 In2 100
18/May/2015:02:05:48 +0000 Out2 100
18/May/2015:15:05:08 +0000 In3 100
18/May/2015:16:05:03 +0000 Out3 100
I am currently using two elapsed functions and 2 aggregate functions as shown below in the config file
Config File
filter{
grok{
match => {"message" => "%{HTTPDATE:timestamp} %{WORD:Event} %{NUMBER:ID}"}
add_tag => ["%{Event}"]
}
date{
match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
}
elapsed {
start_tag => "In1"
end_tag => "Out3"
unique_id_field => "ID"
}
elapsed {
start_tag => "In2"
end_tag => "Out2"
unique_id_field => "ID"
}
if [Event] == "Out2" {
aggregate {
task_id => "%{ID}"
code => "map['time1'] = (event.get('elapsed_time')*1000).to_i"
map_action => "create"
}
}
if [Event] == "Out3" {
aggregate {
task_id => "%{ID}"
code => "map['time2'] = (event.get('elapsed_time')*1000).to_i - map['time1']; event.set('time1', map['time2'])"
map_action => "update"
end_of_task => true
}
}
}
I was able to generate elapsed time fields but was unable to calculate the difference between then using Agreggate filter. Find below my output
Is there anything I am missing?
Any help is appreciated! Thanks in advance