Splunk Search

using variables in a search + to store number of rows

HattrickNZ
Motivator

I have a search | timechart span=h count | streamstats count as row
that gives me 24 rows: (1 full day at an hourly level)

_time   count   row
1   2016-02-20 00:00    2   1
2   2016-02-20 01:00    2   2
...
23  2016-02-20 22:00    2   23
24  2016-02-20 23:00    2   24

what I want to do is get a total of the count and then divide this by (NumberOfRows*2)*100

| timechart span=h count | stats sum(count) as total | eval percent=total/24*2*100 which will give me:

total   percent
1   48  100

How do I set NumberOfRows to be a variable storing the number of rows dynamically, 24 for 1 day, or if I do it for 2 days it would be 48 ....etc.
Or is there a better way of doing this?

0 Karma
1 Solution

maciep
Champion

I feel like there's probably a better way to accomplish what you're trying to get after, but it's late and my brain is shutting down. But to answer your question maybe, I think this should work.

| timechart span=h count | stats sum(count) as total dc(_time) as numRows | eval percent=total/numRows*2*100

that should get you the distinct count of values for _time, which after the timechart should be one for each row.

View solution in original post

maciep
Champion

I feel like there's probably a better way to accomplish what you're trying to get after, but it's late and my brain is shutting down. But to answer your question maybe, I think this should work.

| timechart span=h count | stats sum(count) as total dc(_time) as numRows | eval percent=total/numRows*2*100

that should get you the distinct count of values for _time, which after the timechart should be one for each row.

HattrickNZ
Motivator

tks, | timechart span=h count | stats sum(count) as total dc(_time) as numRows | eval percent=total/(numRows*2)*100 just had to add the brackets.

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 ...