Splunk Search

Why are both of my new time fields are coming out as being the same when using streamstats?

tb5821
Communicator

I'm running my search over the last 7 days and attempting to get the earliest time along with the value of the count field and the latest time along with the value of the count field. but both my new time fields are coming out as being the same! What am I doing wrong?

<search>
    | streamstats earliest(count) as earliest_count by namespace 
    | streamstats earliest(_time) as earliest_time by namespace
    | streamstats latest(_time) as latest_time by namespace
    | streamstats latest(count) as latest_count by namespace
    | where latest_count=earliest_count 
    | eval l_time=strftime(latest_time,"%m/%d/%y %H:%M:%S")
    | eval e_time=strftime(earliest_time,"%m/%d/%y %H:%M:%S")
    | eval time_since_last = e_time - l_time  
    | fieldformat time_since_last = tostring(time_since_last, "duration")
0 Karma
1 Solution

renjith_nair
Legend

@tb5821,

Try eventstats and you could do that in single stretch

     | eventstats earliest(count) as earliest_count,earliest(_time) as earliest_time,latest(_time) as latest_time,streamstats latest(count) as latest_count by namespace 
     | where latest_count=earliest_count 
     | eval l_time=strftime(latest_time,"%m/%d/%y %H:%M:%S")
     | eval e_time=strftime(earliest_time,"%m/%d/%y %H:%M:%S")
     | eval time_since_last = e_time - l_time  
     | fieldformat time_since_last = tostring(time_since_last, "duration")
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

@tb5821,

Try eventstats and you could do that in single stretch

     | eventstats earliest(count) as earliest_count,earliest(_time) as earliest_time,latest(_time) as latest_time,streamstats latest(count) as latest_count by namespace 
     | where latest_count=earliest_count 
     | eval l_time=strftime(latest_time,"%m/%d/%y %H:%M:%S")
     | eval e_time=strftime(earliest_time,"%m/%d/%y %H:%M:%S")
     | eval time_since_last = e_time - l_time  
     | fieldformat time_since_last = tostring(time_since_last, "duration")
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...