# Monitoring Rules

Monitoring Rules in Frends enable Environment-level monitoring and alerting based on Process execution data. They provide automated oversight of integration health by analyzing Promoted Values across multiple Process Instances over specified time intervals.

## What are Monitoring Rules?

Monitoring Rules inspect the executions of all Processes in an Environment as a whole, focusing on the data being processed rather than the technical success of individual Process Instances. They enable you to detect patterns and anomalies that would be difficult to identify by examining single Process executions alone.

Common use cases include:

* Detecting when errors occur multiple times over a time period
* Alerting when integrations are not executed within a specified time
* Monitoring when fewer Process Instances execute than expected
* Identifying when operations take longer than expected

Monitoring Rules are based on Promoted Values from Processes. By targeting specific Promoted Values, you can monitor one or more Processes, or track specific conditions across multiple different Processes.

## Usage

How to use and create Monitoring Rules in Frends.

### Accessing Monitoring Rules

Monitoring Rules are managed at the Environment level. Navigate to **Administration > Monitoring Rules** in Frends, select the target Environment, and click **Create new** to define a new rule. Note that at least **Administrator** role or appropriate permissions are required to create and manage Monitoring Rules.

### Creating a Monitoring Rule

When creating a Monitoring Rule, you define what to monitor by selecting Promoted Values to track. You then specify conditions using thresholds and comparison operators, set time intervals for when and how often to check, and configure actions such as email alerts or Process triggers.

### How Monitoring Rules Work

Monitoring Rules operate on a scheduled basis. Rule series are generated and checked after one full rule interval completes. An additional processing delay (default 10 minutes) ensures all Process log messages and Promoted Values are written to the data store. This delay prevents false alerts by ensuring data completeness. The default delay can be adjusted in the messaging service configuration file using the `MonitoringRuleAlertProcessingDelay` parameter.

If an alert for a rule has already been sent, there is by default a one hour waiting period before new alerts are sent for the same rule. This prevents excessive email notifications.

## Configuration

The following parameters and configuration options are available for Monitoring Rules in Frends.

### Name

Displayed name for the Monitoring Rule. Should be descriptive and indicate what is being monitored and under what conditions.

Example: `OrderProcessing - OrderId Count below 100 in 1 hour`

### Recipients

List of email addresses where to send automated email notification. Separate addresses by comma (`,`).

### Triggered Processes

List of Processes to execute when the Monitoring Rule is triggered. Only Processes that have a Manual Trigger with "Use for Monitoring Rules" option enabled can be selected here.&#x20;

These Processes receive additional reference value which contains information about the triggering Monitoring Rule and the condition in order to act accordingly.

### Filter on variable values

Toggle to select whether to count only the number of specified Promoted Values, or also to filter and match them by their contents.

### Variable to monitor

Specifies which Promoted Value to monitor and what conditions to match.

**Filter operator**: If **Filter on variable values** is enabled, this chooses how to match the value

* `Exists`: As long as the Promoted Variable exists for the execution, it counts
* `Contains`: Value contains the specified text (uses C# `String.Contains` method - does not support wildcards like `*`)
* `Greater Than`: Values greater than specified (Promoted Values must be numeric)
* `Less Than`: Values less than specified (Promoted Values must be numeric)
* `Equals`: Value exactly matches the specified text

**Filter value**: The text or pattern to match against

### Send alert if

Defines the condition that triggers an alert.

**Aggregation type**:

* `Count of variable values`: Counts all matched values of the Promoted Variable
* `Count of distinct variable values`: Counts only unique values of the Promoted Variable
* `Sum of variable values`: Sums numeric values (Promoted Values must be numeric)
* `Maximum of variable values`: Finds the maximum numeric value
* `Count of instances`: Counts Process Instances matching the filter

**Comparison operator**:

* `Greater or equal to`
* `Less or equal to`
* `Not Equal to`

**Threshold value**: The numeric value to compare against

### During time interval

Specifies the time period over which to evaluate the rule. You can specify the interval in minutes or hours.

**Minutes**: Select from 1, 5, 10, 15, 20, or 30 minutes

**Hours**: Enter any hour value from 1 to 24 hours

{% hint style="warning" %}
The time interval must divide 24 hours into equal parts. Intervals always start at midnight (00:00) and repeat throughout the day. If you select an interval that does not divide evenly into 24 hours, some time periods will be excluded from monitoring.&#x20;

Recommended hour values: 1, 2, 3, 4, 6, 8, 12, 24

For example, a 10-hour interval would create monitoring windows at 00:00-10:00 and 10:00-20:00, but the period from 20:00-24:00 would not be monitored because it does not fit a complete 10-hour interval.
{% endhint %}

Monitoring Rules support a maximum interval of 24 hours natively. For longer monitoring periods, custom solutions using triggered Processes and Environment Variables may be required.

### Timezone & date settings

Controls when the Monitoring Rule is active.

**Timezone**: Select the timezone for time-based settings

**Active days**: Allows you to select specific days of the week when the rule should be active.

**Active time**: Allows you to select the time window when the rule should be active.

* **Start time**: Beginning time of active period
* **Stop time**: End time of active period

{% hint style="warning" %}
When using time intervals that do not align with the active time window, the rule may not trigger as expected. Intervals always start counting from midnight.

For example, a 2-hour interval with an active window of 07:00-15:00 may cause missing the first hour of the window.
{% endhint %}

**Disabling holidays:** Allows you to select specific national holidays for specified year that the rule should not be executed.

* **Country**: Which national holidays to choose from
* **Year**: Which year's holidays to choose from
* **Holidays**: Select one or more holidays to not run the rule on

## Reference Values

When a Process is triggered by a Monitoring Rule (using a Manual Trigger with "Use for Monitoring Rules" enabled, and the Process chosen to be executed as alert for a Monitoring Rule), the following reference values are available:

### #trigger.data.monitoringRule (Object)

Object containing information about the triggering Monitoring Rule.

#### emailRecipients (String\[])

List of email recipients defined for the triggering Monitoring Rule.

```csharp
#trigger.data.monitoringRule.emailRecipients
```

#### error (String)

Error message from the Monitoring Rule, explaining why the rule was triggered.

```csharp
#trigger.data.monitoringRule.error
```

#### expectedValue (String)

Contains the Monitoring Rule's condition for triggering an alert.

Example: `"Rule not met, expected GreaterThan 10.0 for 1/14/2022 12:10:00 PM +02:00 over 10 Minutes, but was 4.0000."`

```csharp
#trigger.data.monitoringRule.expectedValue
```

#### name (String)

Name of the triggering Monitoring Rule.

```csharp
#trigger.data.monitoringRule.name
```

#### triggeredProcesses (Object\[])

List of objects containing Process GUID and Agent Group name for all Processes triggered by the Monitoring Rule.

```csharp
#trigger.data.monitoringRule.triggeredProcesses
```

#### variableName (String)

Name of the Promoted Value that the Monitoring Rule monitors.

```csharp
#trigger.data.monitoringRule.variableName
```

## Examples

Here are some common usage scenarios for Monitoring Rules, and how they are set up.

### Alert if number of Process Instances is less than expected

Monitor that at least 100 orders are processed each hour.

**Filter on variable values**: `false`

**Variable to monitor**: `OrderHandlingProcess_OrderId`

**Send alert if**:

* Aggregation: `Count of distinct variable values`
* Operator: `Less than`
* Threshold: `100`

**During time interval**: `1 Hour`

### Alert if errors occur too frequently

Monitor for repeated connection errors.

**Filter on variable values**: `true`

**Variable to monitor**: `ConnectionError`

**Filter operator**: `Contains`

**Filter value**: `timeout`

**Send alert if**:

* Aggregation: `Count of instances`
* Operator: `Greater than`
* Threshold: `10`

**During time interval**: `1 Hour`

### Alert if no files are transferred

Monitor file transfer silence.

**Filter on variable values**: `true`

**Variable to monitor**: `FilesTransferred`

**Filter operator**: `Contains`

**Filter value**: `Success`

**Send alert if**:

* Aggregation: `Count of instances`
* Operator: `Less than`
* Threshold: `1`

**During time interval**: `24 Hours`

**Timezone & date settings**:

* Active days: Monday through Friday
* Between selected times: `06:00` to `18:00`
