Splunk Search

Subtracting two fields

sintjm
Path Finder

I extracted 2 fields called 'Resp_time' and 'Req_time'...Both these fields are integers.
I also changed the values to epoch 

How do I display the difference between the Resp_time and req_time?

Labels (4)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @sintjm ,

as also @yuanliu said, you need a correlation key to correlate the events, if you have, you can use it in a stats command and this is the best solution:

<your_search>
| stats 
    values(Resp_time) AS Resp_time 
    values(Req_time) AS Req_time 
    BY key
| eval diff=Resp_time-Req_time

If you haven't and you're sure that events are always sequential, you could use the transaction command:

<your_search>
| transaction maxevents=2
| table duration

Ciao.

Giuseppe

 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @sintjm ,

if they are integers or they are in epochtime, you can calculate the difference using eval command:

<your_search>
 | eval diff=Resp_time-Req_time

Ciao.

Giuseppe

 

0 Karma

sintjm
Path Finder

Hi thanks but the problem is they are not from the same events as they are separate

sintjm_0-1721925754156.png

 

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @sintjm ,

as also @yuanliu said, you need a correlation key to correlate the events, if you have, you can use it in a stats command and this is the best solution:

<your_search>
| stats 
    values(Resp_time) AS Resp_time 
    values(Req_time) AS Req_time 
    BY key
| eval diff=Resp_time-Req_time

If you haven't and you're sure that events are always sequential, you could use the transaction command:

<your_search>
| transaction maxevents=2
| table duration

Ciao.

Giuseppe

 

sintjm
Path Finder

thanks, I used a correlation key to correlate the events and it worked. 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You will need a common value in the two types of events to correlate events.  For example, if each pair has a unique transaction ID, you can do

| stats values(Resp_time) as Resp_time values(Req_time) as Req_time by transaction_id
| eval Resp_time - Req_time

Alternatively, if you have some other ways to determine a pairing, e.g., the two always happen within a deterministic interval,  e.g., request comes in at 5 minute into the hour, a unique response is sent within the hour and NO other request would come in during the same hour, you can use that as criterion.  There may be other conditions where you would use transaction.  Unless you give us the exact condition, mathematically there is no solution.

sintjm
Path Finder

Helped a lot, thanks.

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...