Splunk Search

calculate duration of connection

jalfrey
Communicator

I have these two log messages

Jul 2 10:21:50 10.197.1.254 id=firewall sn=0017C5C027C1 time="2013-07-02 17:21:50 UTC" fw=67.115.118.49 pri=6 c=262144 m=98 msg="Connection Opened" n=565679 src=192.168.168.65:1330:MGMT dst=192.168.168.169:443:MGMT proto=tcp/https sent=64

ul 2 10:21:58 10.197.1.254 id=firewall sn=0017C5C027C1 time="2013-07-02 17:21:57 UTC" fw=67.115.118.49 pri=6 c=1024 m=537 msg="Connection Closed" n=606900 src=192.168.168.65:1330:MGMT dst=192.168.168.169:443:MGMT proto=tcp/https sent=670 rcvd=473 spkt=8 rpkt=6 cdur=7366

As you can see the first one is for "Connection Opened" and the second "Connection Closed". Both the src and dst are the same so I believe this is a single stream. How do I calculate the total duration of this connection?

0 Karma

lguinn2
Legend

There are many ways to tackle this problem. One is to use the transaction command, which will automatically create a field called duration for you. This example creates the transactions and formats a nice table

yoursearchhere ("Connection Opened" OR "Connection Closed")
| transaction src dst startswith="Connection Opened" endswith="Connection Closed"
| table _time as StartTime duration src dst
| fieldformat duration=tostring(duration,"duration")
| fieldformat StartTime=strftime(StartTime,"%x %X")
0 Karma

Jon_Webster
Splunk Employee
Splunk Employee

If you are getting your timestamps indexed correctly, then the "duration" field which is created for every "transaction" event will show you your duration in seconds. In your example the duration should be "8", as the difference between the 10:21:50 and 10:21:58 in your timestamps.

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...