Splunk Search

help to write the stats query

dhavamanis
Builder

we have three column for the below query _time, response_time and count,

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" | stats count by _time, response_time

now we want to count the results like this,

_time, (Sametime shouldnt repeat)
Max(response_time)
count - (should include all the events count)

Can you please help me to get this query.

Tags (2)
0 Karma
1 Solution

dhavamanis
Builder

Thanks musskopf, I have tried the below and its working fine for me,

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_ID="4b784d93d98941e087bbe75b1c2b9fbe" |stats count as cevent by _time, response_time | stats max(response_time) as mresponse, sum(cevent) as sevent by _time | sort by _time desc

View solution in original post

0 Karma

dhavamanis
Builder

Thanks musskopf, I have tried the below and its working fine for me,

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_ID="4b784d93d98941e087bbe75b1c2b9fbe" |stats count as cevent by _time, response_time | stats max(response_time) as mresponse, sum(cevent) as sevent by _time | sort by _time desc

0 Karma

musskopf
Builder

Hello dhavamanis,

Is that what you're looking for?

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" | eventstats count AS total_events | stats count, values(total_events), max(response_time) by _time

Just for you reference, the command eventstats is similar to stats, but instead of create a table, it'll add the result to each event as an additional field and you can use it on the next pipe.

Also, you might want to add something like | bucket span=10m _time after your search to group things together

If that's not what you're after, pls post an table showing how the result should looks like.

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!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...