Splunk Search

help on basic questions about stats avg on a specific period

jip31
Motivator

hi

In the stats avg() below, I want to do an avg on the last month
So do I have to specify it with earliest=-1mon latest=now or do I have to use bucket _time span=1mon?

| stats avg(sent_data) as sent_data avg(received_data) as received_data, values(SITE) as SITE by USERNAME 
| eval sent_data=round(sent_data, 2) 
| eval received_data=round(received_data, 2) 
| sort +sent_data +received_data

Thanks

Tags (2)
0 Karma
1 Solution

justinatpnnl
Communicator

Are you trying to get the average for the previous month or the last ~30 days? For example, are you looking for June or June 16 - July 16? The easiest would be to pick your actual time range from the Time Picker controls.

Taking your examples, you most likely want to do something like you specified: earliest=-1mon latest=now. But make sure this is doing what you want. You are telling Splunk to return the data since June 16th starting at the current time. If instead you want the previous month, you can do this instead: earliest=-1mon@mon latest=@mon. This will search for data between 2019-06-01 00:00:00 and 2019-06-30 23:59:59.

bucket _time span=1mon is not going to do much for you unless your also include the _time in your stats command:

| stats avg(sent_data) as sent_data avg(received_data) as received_data, values(SITE) as SITE by _time, USERNAME

This will round each time stamp down to the first of each month. If you are trying to get the last 30 days, this won't quite do what you want. It will also depend on the time range specified.

View solution in original post

0 Karma

justinatpnnl
Communicator

Are you trying to get the average for the previous month or the last ~30 days? For example, are you looking for June or June 16 - July 16? The easiest would be to pick your actual time range from the Time Picker controls.

Taking your examples, you most likely want to do something like you specified: earliest=-1mon latest=now. But make sure this is doing what you want. You are telling Splunk to return the data since June 16th starting at the current time. If instead you want the previous month, you can do this instead: earliest=-1mon@mon latest=@mon. This will search for data between 2019-06-01 00:00:00 and 2019-06-30 23:59:59.

bucket _time span=1mon is not going to do much for you unless your also include the _time in your stats command:

| stats avg(sent_data) as sent_data avg(received_data) as received_data, values(SITE) as SITE by _time, USERNAME

This will round each time stamp down to the first of each month. If you are trying to get the last 30 days, this won't quite do what you want. It will also depend on the time range specified.

0 Karma

jip31
Motivator

hi
i am looking for June 16 - July 16 so i am going to use earliest=-1mon latest=now
thanks

0 Karma

richgalloway
SplunkTrust
SplunkTrust

To get stats for a month you must have a month of data so earliest=-1mon is a minimum. For just one month, bucket is not needed.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...