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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...