Getting Data In

Duration between messages

wscott12
New Member

Hi, I have messages in Splunk like:

{ [-] 
id: ABC
message: test1
timestamp: 2017-08-07T16:38:38+00:00 }
{ [-] 
id: BAC
message: test2 
source: client 
timestamp: 2017-08-07T16:38:38+00:00 }

These messages show up for each id. I would like to get duration between the first message "test" showing up and the second message "test2" by id. Maybe get the average duration for both messages showing up after tying each message to an id.

So basically, how can I get the average duration per ID How can I do that in Splunk?

For duplicate ids, I need to get the worst duration for that ID. So no duplicates. Thanks!

0 Karma

DalJeanis
Legend

Both of the answers assume that hte guid was supposed to be the same between the two messages. Is that accurate? If so, please edit the question to make those the same. If not, please edit to indicate how the programmer is going to determine that those two messages are in any way related to each other.

Thanks!

0 Karma

wscott12
New Member

I updated the question please check

0 Karma

woodcock
Esteemed Legend

Like this:

... | stats range(_time) AS gap BY guid
| stats avg(gap)

richgalloway
SplunkTrust
SplunkTrust

One approach, although not the fastest, is to use transaction. This command automatically computes the time difference between the starting and ending events and stores the result in a field called 'duration'. You can then calculate an average of that field.

... | transaction guid startswith="analyticsLoaded" endswith="doneWithAnalytics" | stats avg(duration) as AvgDuration by guid
---
If this reply helps you, Karma would be appreciated.
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!

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...