Imagine you're Jeff Bezos and you own a few servers. You sell compute on these servers to customers and you want to make sure that you always have enough computer power to meet demand. This means when overall RAM consumption approaches the max RAM of your servers you must buy more servers so your customers never have an outage! But it takes at least a week to set everything up!
In this scenario, we need to be alerted to a metric hitting a maximum ahead of time. This is done with a forecasted value.
We can use the R integration to predict n days ahead and trigger a pulse alert to notify us when predicted values breach a threshold value.
In this example, we will use the Prophet library to forecast our data, but any library can be used - even regression.
As an example, let’s look at a time series of the log daily page views for the Wikipedia page for Peyton Manning. Peyton Manning provides a nice example because it illustrates some of Prophet’s features, like multiple seasonality, changing growth rates, and the ability to model special days (such as Manning’s playoff and superbowl appearances). The CSV is available here.
Steps to implement
1. Elasticube Setup:
In the Elasticube, break up the date you will forecast over into independent Year, Month, and Day integer columns using custom columns for each.
custom column name: function
2. RServe & Environment Setup
Run RServe and download the following libraries to R
3. Sisense Indicator and Function Setup
Paste the following code into an indicator's function editor.
df <- data.frame(y=args[], year=args[], month=args[], day=args[]);
df <- df %>% unite('ds', year, month, day, sep='-', remove = FALSE);
df <- df[c('ds', 'y')];
df$ds <- as.Date(df$ds , format = '%Y-%m-%d');
m <- prophet(df);
future <- make_future_dataframe(m, periods = args[], include_history = FALSE);
forecast <- predict(m, future);
In the code above the arguments to the function are columns y (as all items), year (as all items), day (as all items), and the number 60.
- y: the value to forecast
- year: the integer year portion of the date
- month: the integer month portion of the date
- day: the integer day portion of the date
- 60: the parameter that determines how many days into the future to forecast
Save the widget.
This number represents the maximum value among forecasted values.
4. Creating the Pulse Alert
On the widget you just made, create a pulse alert, and set a threshold. Use the "greater than" option.
When any of the values in the forecast go above the threshold you will be notified!
This works with data security, so each tenant's data will be forecasted and evaluated against the threshold when the elasticube is built. Only users who's forecasted values are greater than the threshold will be notified.