Splunk Search

Calculating the average duration of an entire group

yepyepyayyooo
New Member

Good morning Splunkers, I trust everyone is remaining safe.

Ultimately, I'm attempting to obtain the overage connection duration of external IPs for each destination zone based on firewall logs. The reporting period would be 24h. So the output I'd be looking for is something like this:

dest_zone AvgDuration
ABC App 00:00:07:123
123 Zone 00:00:13:123
Cisco VPN 00:07:12:004

Please see my non-working query below:

index="pan_logs" sourcetype="pan_traffic" action="allowed"
| eventstats earliest(_time) as earliest_time by src_ip
| eventstats latest(_time) as latest_time by src_ip
| eval Duration=latest_time-earliest_time
| stats avg(Duration) as AvgDuration by src_ip
| eval AvgDuration = strftime(AvgDuration/1000 , "%H:%M:%S:%3Q")
| stats values(AvgDuration) by dest_zone

As always, any help is greatly appreciated.

Labels (1)
Tags (1)
0 Karma
1 Solution

adonio
Ultra Champion

seems like your | stats doesnt take into consideration the field dest_zone so its being stripped away and cannot be used
try to add it as a split by to your | stats what does it looks like?
.... | stats avg(Duration) as AvgDuration by src_ip dest_zone
| eval AvgDuration = strftime(AvgDuration/1000 , "%H:%M:%S:%3Q")
| stats values(AvgDuration) by dest_zone ...

also maybe try this:

index="pan_logs" sourcetype="pan_traffic" action="allowed"
 | stats min(_time) as earliest_time max(_time) as latest_time by src_ip dest_zone
 | eval Duration=latest_time-earliest_time
 | stats avg(Duration) as AvgDuration by dest_zone
 | eval AvgDuration = strftime(AvgDuration/1000 , "%H:%M:%S:%3Q")

hope it helps

View solution in original post

adonio
Ultra Champion

seems like your | stats doesnt take into consideration the field dest_zone so its being stripped away and cannot be used
try to add it as a split by to your | stats what does it looks like?
.... | stats avg(Duration) as AvgDuration by src_ip dest_zone
| eval AvgDuration = strftime(AvgDuration/1000 , "%H:%M:%S:%3Q")
| stats values(AvgDuration) by dest_zone ...

also maybe try this:

index="pan_logs" sourcetype="pan_traffic" action="allowed"
 | stats min(_time) as earliest_time max(_time) as latest_time by src_ip dest_zone
 | eval Duration=latest_time-earliest_time
 | stats avg(Duration) as AvgDuration by dest_zone
 | eval AvgDuration = strftime(AvgDuration/1000 , "%H:%M:%S:%3Q")

hope it helps

DalJeanis
Legend

Nice. You also combined the eventstats to make them more efficient.

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...