Adding a custom Optimizer rule


Use the Rules page in the Administration tab to create, configure, and manage Optimizer rules to generate alerts and recommendations. For information about Optimizer rules, see Configuring-and-managing-Optimizer-rules.

You can create an Optimizer rule based on a predefined template or create a custom rule. This topic explains the procedure to add a custom rule.

Review the existing templates before you create a new custom rule. For details about creating a template-based rule, see Adding-a-template-based-Optimizer-rule.

Adding a custom rule 

  1. Click Administration > OPTIMIZER > Rules
  2. In the Optimizer Rules page, click Add new rule.
  3. In the New Optimizer rule page, enter values and make appropriate selections for the following properties:

    Properties marked with ✅️ are available only while building a rule in Advanced mode. To switch (toggle) to Advanced mode, click Advanced.

  4. Click Save.

The rule is saved and enabled by default. The rule is listed in the Optimizer rules table. The rule is triggered to run based on the Optimizer task that is associated with the rule.

Examples of formulas

The following table contains some examples of formulas that you can add to the Formula field. You can use the format as Apache Velocity template. For information on the Apache Velocity template, Apache Velocity template.

Goal

Example of formula

Generate an alert on overprovisioned datastores based on metric values (DSTORE_PROVISIONED is greater than DSTORE_SIZE)

alerted = (DSTORE_PROVISIONED.value > DSTORE_SIZE.value);

Know if data for an indicator/metric (IND_DAYS_TO_SATURATION) is available

if (IND_DAYS_TO_SATURATION) { ... }

Get an indicator (IND_DAYS_TO_SATURATION) value

IND_DAYS_TO_SATURATION.value

Get a specific subresource value, for example CPU

IND_DAYS_TO_SATURATION.subresource("CPU").value;

Know if data for a certain subresource is available, for example CPU

if (IND_DAYS_TO_SATURATION.hasSubresource("CPU")) { ... }

Set a value or threshold in the output

point.value0 = some_value; point.threshold0 = a_threshold; ...;
point.value20 = some_value; point.threshold20 = a_threshold;

Add a metric (resource) to an alerted subresource, for example CPU

point.addAlertedResource("CPU");

Generate an alert when the days to saturation for CPU, memory, or storage is more than the threshold value

var res = false;
if(Math.round(IND_DAYS_TO_SATURATION.value)<=30) {
if(IND_DAYS_TO_SATURATION.hasSubresource("CPU") && IND_DAYS_TO_SATURATION.subresource("CPU").value<30) {
res = true;
}
if(IND_DAYS_TO_SATURATION.hasSubresource("MEMORY") && IND_DAYS_TO_SATURATION.subresource("MEMORY").value<30) {
res = true;
}
if(IND_DAYS_TO_SATURATION.hasSubresource("STORAGE") && IND_DAYS_TO_SATURATION.subresource("STORAGE").value<30) {
res = true;
}
}
alerted = res;

Screenshot with sample data

22.2.01_rule_custom_formula_ex.png

Examples of parameters

Define parameters as per the following syntax:

<name of parameter> | <description> | <threshold value> | <type>

Where <type> can be a number or a string.

Parameters are used to add new thresholds that can be used in formulas. You can define multiple parameters by separating them with a newline character (press Enter).

The following table contains some examples of parameters that you can add to the Parameters field.

Goal

Parameter definition

To create a threshold: Days to saturation – Critical threshold, set to a value of 7 (days)

dts_th_crit|Days to saturation critical threshold|7|number

To create a threshold: Days to saturation – Warning threshold, set to a value of 30 (days)

dts_th_warn|Days to saturation warning threshold|30|number

Screenshot with sample data

22.2.01_rule_custom_param_ex.png

Example of using parameters in formulas

The following table contains some examples of parameters that are used in a formula in a custom Optimizer rule.

Goal

Parameter definition

Use the following thresholds in the formula:

  • dts_th_crit|Days to saturation critical threshold|7|number
  • dts_th_warn|Days to saturation warning threshold|30|number

var res = false;
var dts_th = Math.max(dts_th_crit, dts_th_warn);
if (IND_DAYS_TO_SATURATION.value <= dts_th)
{
res = true;
}

Screenshot with sample data

22.2.01_rule_custom_ex.png

Example of recommendation text or description

The following code block contains an example of a Velocity template description that you can add to the Recommendation text field in the custom Optimizer rule. 

#if ( $point.value0>0)  Forecasted saturation in $numberFormatter.format($point.value0) days. #else Some resources are already saturated. #end
Details:
#if ($point.alertedResources.contains('CPU'))  
  #if ($point.value1>0) CPU will saturate in $numberFormatter.format($point.value1) days.
  #else CPU exhausted.
  #end
#end
#if ($point.alertedResources.contains('MEMORY'))  
  #if ($point.value2>0) Memory will saturate in $numberFormatter.format($point.value2) days.
  #else Memory exhausted.
  #end
#end
#if ($point.alertedResources.contains('STORAGE'))  
  #if ($point.value3>0) Storage will saturate in $numberFormatter.format($point.value3) days.
  #else Storage exhausted.
  #end
#end


You can use formatting functions that the Velocity template provides in the Recommendation text field. The following table describes some of these formatting functions.

Structure of a recommendation output

A recommendation output is structured as follows:

alert.cond.1.rule.recomm.vtl = 
Allocate more $stringFormatter.formatList($point.alertedResources)

Setting a status for alerts in the recommendation output

To set a critical status for an alert, you must set the severity as per the ALERT_STATUS table.

For example, to generate a Critical alert whose ID is 3, the structure is as follows:

alert.cond.1.severity = 3

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*