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"

Get Updates on the Splunk Community!

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud  In today’s fast-paced digital ...

Observability protocols to know about

Observability protocols define the specifications or formats for collecting, encoding, transporting, and ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...