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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...