Splunk Search

How to break out eventstats by day?

fmatera
Explorer

I have an eventstats search that is working well. What I am having a difficult time with is that I am unable to return results by day. The field apiid is a common id that ties together multiple events. I need the answer field fromm the smallest apiid in the group and the cr_date from the highest apiid. Here is what I have so far:

    base search 
   | eventstats max(id) as maxid min(id) as minid by apiid 
   | eval mintime=if(id=minid,answer,null()) 
   | eval maxtime=if(id=maxid,cr_date,null()) 
   | stats values(mintime) as mintime values(maxtime) as maxtime by apiid 
   | convert mktime(*time) timeformat="%Y-%m-%d %H:%M:%S" 
   | eval diff=abs(mintime-maxtime) 
   | stats avg(diff) as AvgTime 
   | fieldformat AvgTime=tostring(AvgTime, "duration") 
   | eval AvgTime = round(AvgTime,2)

I have tried different combinations of bucket and timechart but have been unsuccessful.
Thanks in advance!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

What results are you getting so far? What have you tried with bucket and timechart?

The stats command is only returning the 'AvgTime' field. Without also returning _time, timechart won't work.

---
If this reply helps you, Karma would be appreciated.
0 Karma

fmatera
Explorer

Thanks. For bucket I added
|bucket span=1d _time
After base search. When running over 7 days, it returns 1 number where I would expect 1 number per day

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...