Splunk Search

predict future_timespan value as a calculated variable

danan5
Path Finder

Hi,
I am trying to use the predict function to predict hourly values through to the end of the current day. To do this I need to pass to the future_timespan option a decreasing number as the day progresses. ie at midday future_timespan = 12, at 3pm future_timespan=9 etc.

I have some fairly ugly eval statements that give me a value of the number of hours remaining in the current day, however, I don't see how I can pass a value back to the command as a variable.

Any hints greatly appreciated.
David

0 Karma
1 Solution

danan5
Path Finder

So finally worked out how to do it, was a knowledge gap on my part. I didn't understand the "." option in the eval command to concatenate a string with a calculated value, and the sub search returning it all as an option/variable to the predict command.

Below is an example, generating prediction of data ingest through to the end of the current day.

index=_internal source=license_usage.log type=Usage earliest=@d | eval gb=b/1024/1024/1024
| reverse
| accum gb as totalb
| timechart last(totalb) span=1m as tc_totalb
| predict tc_totalb algorithm=LLT holdback=1 [| gentimes start=-1 | eval search="future_timespan=".round((relative_time(now(),"+1d@d")-now())/60) | table search] AS predicted_usage
| eval upper95(predicted_usage)=if(_time<=now(), predicted_usage, 'upper95(predicted_usage)' )
| eval lower95(predicted_usage)=if(_time<=now(), predicted_usage, 'lower95(predicted_usage)' )
| rename tc_totalb as "Data Ingested"

View solution in original post

danan5
Path Finder

So finally worked out how to do it, was a knowledge gap on my part. I didn't understand the "." option in the eval command to concatenate a string with a calculated value, and the sub search returning it all as an option/variable to the predict command.

Below is an example, generating prediction of data ingest through to the end of the current day.

index=_internal source=license_usage.log type=Usage earliest=@d | eval gb=b/1024/1024/1024
| reverse
| accum gb as totalb
| timechart last(totalb) span=1m as tc_totalb
| predict tc_totalb algorithm=LLT holdback=1 [| gentimes start=-1 | eval search="future_timespan=".round((relative_time(now(),"+1d@d")-now())/60) | table search] AS predicted_usage
| eval upper95(predicted_usage)=if(_time<=now(), predicted_usage, 'upper95(predicted_usage)' )
| eval lower95(predicted_usage)=if(_time<=now(), predicted_usage, 'lower95(predicted_usage)' )
| rename tc_totalb as "Data Ingested"

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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