Splunk Search

How to calculate ratios using a single previously calculated value to divide by?

Magrilloc
New Member

I am calculating a bunch of rates and I would like to take all of the rates I have calculated and divide by one of the previously calculated rates. I can get the first two columns below no problem. Here is the search I am currently using (made to be generic):

index=index Env=myEnv Name=requests | stats sum(Rate) as avgRate by _time, Server | stats avg(avgRate) as AvgRate by Server

alt text

0 Karma

woodcock
Esteemed Legend

If you need 500 from your list, then you can use something like this:

index=index Env=myEnv Name=requests | stats sum(Rate) as avgRate by _time, Server | stats avg(avgRate) as AvgRate by Server | eventstats last(rate) AS lastRate min(rate) AS minRate | eval lastRatio = rate / lastRate | eval minRatio = rate / minRate
0 Karma

somesoni2
Revered Legend

Assuming previously calculated rate is the last available rate OR minimum rate (based on your sample values), try like this

index=index Env=myEnv Name=requests | stats sum(Rate) as avgRate by _time, Server | stats avg(avgRate) as AvgRate by Server | eventstats min(AvgRate) as previousRate | eval Ratio=AvgRate/previousRate

You can replace min(AvgRate) by last(AvgRate) OR any other appropriate function.

0 Karma

jkat54
SplunkTrust
SplunkTrust

Which is the previously calculated rate you want to use?

It appears 500 is what you want to use but it's a bit confusing... see if this gives you ideas:

... | stats sum(Rate) as sumRate by Server,_time | eval ratio=sumRate/[search ... | stats avg(avgRate) as avgRate | return $avgRate] | table _time, Server, sumRate, ratio
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...