Splunk Search

How to write a search to calculate the response time from my two sample events?

karthi2809
Builder
12/16/16
6:09:57.022 AM  
[2016-12-16 06:09:57,022][LOG ][WARN ] transid=xxx; Path=PQ; OperationName=UP; TransactionStatus=SUCCESS; CaptureLocation=Response

12/16/16
6:09:56.863 AM  
[2016-12-16 06:09:56,863][LOG ][WARN ] transid=xxx; Path=PQ; OperationName=UP; RequestPayload=U-900M87282; CaptureLocation=Request
0 Karma

niketn
Legend

Try the following stats command. You should filter/join results in your base search (i.e. if Path and OperationName have static values, then use the values in place of asterix *.

Duration is calculated as the difference between earliest and latest events matched by the stats command containing both Request and Response. It is in seconds which you can change to other time format as per your need. Second search can be used to set conditions based on various scenarios like eventcount=1 implies only request no response.

 <Your Base Search> "[LOG ][WARN ]" (CaptureLocation="Request" OR CaptureLocation="Response") Path=* OperationName=* 
    | stats count as eventcount earliest(_time) as earliesttime latest(_time) as latesttime values(TransactionStatus) as TransactionStatus values(RequestPayload) as RequestPayload values(CaptureLocation) as CaptureLocation by transid, Path, OperationName 
    | search eventcount>1 AND TransactionStatus= "SUCCESS" AND CaptureLocation="Request" AND CaptureLocation="Response" 
    | eval duration=latesttime-earliesttime 
    | eval earliesttime=strftime(earliesttime,"%Y/%m/%d %H:%M:%S,%3N") 
    | eval latesttime=strftime(latesttime,"%Y/%m/%d %H:%M:%S,%3N")

PS: Depending on the use case if there is always Request first and Only one Response per transaction ID you can also set eventcount=2 in the inner search condition.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

somesoni2
Revered Legend

Try this

your base search CaptureLocation=Response OR CaptureLocation=Request
| chart max(_time) over transid over CaptureLocation
| eval Response_Time=Response-Request

OR

your base search CaptureLocation=Response OR CaptureLocation=Request
| transaction transid startswith="CaptureLocation=Request" endswith="CaptureLocation=Response"
| rename duration as Response_Time

richgalloway
SplunkTrust
SplunkTrust

What is your question?

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...