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!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...