# Delay calculation between two send/receive events

**URL:** <https://discuss.elastic.co/t/delay-calculation-between-two-send-receive-events/211842>\
**Category:** Logstash\
**Created:** [December 13, 2019, 8:11pm UTC](https://discuss.elastic.co/t/delay-calculation-between-two-send-receive-events/211842 "2019-12-13T20:11:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sreekanth3](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sreekanth3](https://discuss.elastic.co/u/Sreekanth3)\
**Post date:** [December 13, 2019, 8:11pm UTC](https://discuss.elastic.co/t/delay-calculation-between-two-send-receive-events/211842/1 "2019-12-13T20:11:43Z")

</div>

The Delay on the server should be calculated on the actual server,  
if the duration between Receive EventID on Server A and Send EventID on Server b (the same server) is 24 minutes , it should shows it on that specific server (Server A) not the next server...However, if there is a delay between Send EventID of Server A and Receive EventID of Server B, then it is better to show it on Server B .

if [event\_id] == "SEND" or [event\_id] == "RECEIVE"  
{  
aggregate {  
task\_id =\> "%{message\_id}"  
code =\> "  
require 'time'  
if event.get('event\_id') == 'RECEIVE'  
if ! map['AT'] and ! map['BT']  
map['AT'] = event.get('date\_time')  
event.set('delay\_sec', Time.iso8601(map['AT']).to\_f - Time.iso8601(event.get('date\_time')).to\_f)  
else  
if map['BT']  
map['AT'] = event.get('date\_time')  
if Time.iso8601(map['AT']).to\_f \> Time.iso8601(map['BT']).to\_f  
event.set('delay\_sec', Time.iso8601(map['AT']).to\_f - Time.iso8601(map['BT']).to\_f)  
else  
event.set('delay\_sec', Time.iso8601(map['BT']).to\_f - Time.iso8601(map['AT']).to\_f)  
end  
else  
map['tempAT'] = event.get('date\_time')  
if Time.iso8601(map['AT']).to\_f \> Time.iso8601(map['tempAT']).to\_f  
event.set('delay\_sec', Time.iso8601(map['AT']).to\_f - Time.iso8601(map['tempAT']).to\_f)  
map['AT'] = map['tempAT']  
else  
event.set('delay\_sec', Time.iso8601(map['tempAT']).to\_f - Time.iso8601(map['AT']).to\_f)  
map['AT'] = map['tempAT']  
end  
end  
end  
else  
if ! map['BT'] and map['AT'] and event.get('event\_id') == 'SEND'  
map['BT'] = event.get('date\_time')  
if Time.iso8601(map['BT']).to\_f \> Time.iso8601(map['AT']).to\_f  
event.set('delay\_sec', Time.iso8601(map['BT']).to\_f - Time.iso8601(map['AT']).to\_f)  
else  
event.set('delay\_sec', Time.iso8601(map['AT']).to\_f - Time.iso8601(map['BT']).to\_f)  
end  
else  
if map['AT']  
map['BT'] = event.get('date\_time')  
if Time.iso8601(map['BT']).to\_f \> Time.iso8601(map['AT']).to\_f  
event.set('delay\_sec', Time.iso8601(map['BT']).to\_f - Time.iso8601(map['AT']).to\_f)  
else  
event.set('delay\_sec', Time.iso8601(map['AT']).to\_f - Time.iso8601(map['BT']).to\_f)  
end  
else  
if !map['BT']  
map['BT'] = event.get('date\_time')  
event.set('delay\_sec', Time.iso8601(map['BT']).to\_f - Time.iso8601(event.get('date\_time')).to\_f)  
else  
map['tempBT'] = event.get('date\_time')  
if Time.iso8601(map['BT']).to\_f \> Time.iso8601(map['tempBT']).to\_f  
event.set('delay\_sec', Time.iso8601(map['BT']).to\_f - Time.iso8601(map['tempBT']).to\_f)  
map['BT'] = map['tempBT']  
else  
event.set('delay\_sec', Time.iso8601(map['tempBT']).to\_f - Time.iso8601(map['BT']).to\_f)  
map['BT'] = map['tempBT']  
end  
end  
end  
end  
end  
"  
} }

This is the code i was using for calculating difference . It works for the event set  
send send receive receive(SSRR)  
SRSR,RSRS,RRSS....  
But not for the events like RRRS , SSSR .

IS there any way to have the delay calculation for any kind of events.

---

<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:** [January 10, 2020, 8:18pm UTC](https://discuss.elastic.co/t/delay-calculation-between-two-send-receive-events/211842/2 "2020-01-10T20:18:04Z")

</div>

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