Splunk Search

how can I find the average of a field in 2 different timeline

SridharS
Path Finder

Hi, I need to find the average value of a field at 2 different time. One is 4 days before and other is 1 day before. I used the below query but am not able to fetch the "1 day" before data. Any advice is appreciated!!

search........|stats avg(cpu_usage) as average| untable _time Metrics Value |eval Date=if(_time=relative_time(-1d,"-4d"), "Latest","Earliest") |chart first(Value) over Metrics by Date limit=0

Tags (2)
0 Karma

somesoni2
Revered Legend

After your stats there is no field called _time hence remaining search doesn't give the results you want. Try something like this

your base search | bucket span=1d _time | stats avg(cpu_usage) as average by _time | eval Date=if(_time=relative_time(now(),"-1d@d"), "Latest","Earliest") | eval Metrics="Average CPU Usage"  |chart first(Value) over Metrics by Date limit=0
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...