Splunk Search

difference of two values of same field inside a transcation

KarunK
Contributor

Hi ALL,

I am using a transaction command to group two events together, "connect" and "disconnect". Both the events have a common field called bytes and I need to get the difference of the bytes delivered during the disconnect event and connect event.

How can I achieve this ?

(sourcetype="access" event="*connect" status="200") | transaction c_ip eventttype startswith="connect" endswith="disconnect"

Thanks in Advance

Aappreciate your help.

Tags (1)
0 Karma
1 Solution

Ayn
Legend

Use mvlist=t as a parameter to transaction to make sure you're getting field values in the correct (chronological) order, then use mvindex to get the first and last value for bytes.

... | transaction mvlist=t c_ip eventtype startswith="connect" endswith="disconnect" | eval bytesdiff=tonumber(mvindex(bytes,-1))-tonumber(mvindex(bytes,0))

View solution in original post

Ayn
Legend

Use mvlist=t as a parameter to transaction to make sure you're getting field values in the correct (chronological) order, then use mvindex to get the first and last value for bytes.

... | transaction mvlist=t c_ip eventtype startswith="connect" endswith="disconnect" | eval bytesdiff=tonumber(mvindex(bytes,-1))-tonumber(mvindex(bytes,0))

KarunK
Contributor

Thanks Ayn. It worked....

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...