Splunk Search

How can I pair search results from two different queries where only time is different?

plajcsi
Engager

I have a query where I get "STARTED" and "FINISHED" status events for the same methods.
e.g.
index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status

| sort start_time

for this query I get more, let's say 3 results where everything is the same for the event, except event _time

also I would like to get "FINISHED" events so the same only with finished
index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time

I will always get the same number of events for both queries.
Since it is sorted I would need to pair the first started with first finished,  second started with the second finished and so on, and get the duration (end_time - start_time), but how?

So what I would like to see is, let's say if I have 2 started and 2 finished events, and as I mentioned only the time is different(between the 2 started events so I cannot use anything else):

source_typemethodstart_timeend_timeduration
XgetCusips 12164
XgetCusips 18202


I was thinking to iterate on the events somehow and map them the 1st to the 1st, 2nd to 2nd, but no idea if this is even doable.

Hope I have explained it clearly.

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Since "everything is the same" and you "get the same number of events for both queries" and "it is sorted", you could try using appendcols

index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status
| sort start_time
| appendcols
[ search index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time]
| eval duration=end_time-start_time

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Since "everything is the same" and you "get the same number of events for both queries" and "it is sorted", you could try using appendcols

index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status
| sort start_time
| appendcols
[ search index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time]
| eval duration=end_time-start_time

plajcsi
Engager

Yepp, that works fine, thank you so much for the help! 🙂

0 Karma
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...