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 (3)
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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Get Agentic with Splunk Lantern: Connect to Cisco Cloud Control, Transform ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

July Community Events: Master ITSI 5.0 & Automate Splunk

Struggling with alert fatigue or feeling like you're spending more time on infrastructure maintenance than ...

New Release of Federated Search: Bringing Splunk Analytics to More of Your Data

Organizations today are generating more data than ever and storing it across cloud object stores, data lakes, ...