# Create Alarms and Actions

{% hint style="info" %}
**Prerequisite:** Make sure your account has **Monitoring** [<mark style="color:blue;">privileges</mark>](https://docs.ionos.com/sections-test/guides/observability/monitoring-as-a-service/user-permissions#set-user-privileges) enabled in the user group.‌
{% endhint %}

## Create an Alarm

1. In the **DCD**, go to the **Menu** > **Management** > **Monitoring**.
2. In the **Monitoring Manager**‌, select **Create** in the **Alarms** tab.‌
3. A drop-down list will open up. Enter the following values to create an alarm:‌

* **Name:** Enter an appropriate name.
* **Server:** Select a virtual instance.
* **Metric:** Select the relevant metric.
* **Unit:** Select either of the following values:
  * **Total:** Select the **Total** value for absolute numbers. Example: CPU utilization. **Total** is not supported for other metrics except if you use the **Delta** aggregation.
  * **Per second:** Select it for per-second rate.
  * **Per minute:** Select it for per-minute rate.
  * **Per hour:** Select it for per-hour rate.
* **Threshold Type:** Define equality of value.
* **Threshold:** Enter the threshold value.
* **Range:** Define the time range within which the threshold must exceed the configured parameter limits before triggering an alarm event. The minimum time allowed is **120 seconds**.
* **Range Aggregation:** Time range aggregation types are **Average** or **Delta**.
  * **Average:** Calculates the average of the defined metrics for all samples collected within the defined range. The average metric must be outside the configured parameter for the defined range to trigger an action event. This range aggregation is useful for detecting constant load patterns.
  * **Delta:** Compares the change of the defined metric during the defined range. This range aggregation helps detect significant positive or negative spikes within the load patterns.
* **Alarm Delay:** Define the duration between the monitoring metric exceeding the configured threshold parameters and sending an alarm notification. The minimum time allowed is zero seconds, which will trigger an action event immediately once the defined criteria are fulfilled. You can also delay the alarm notification by setting a higher value. Setting a higher alarm delay will consider further metric samples in the calculation and continue shifting the range as time passes. As a result, the system may return to its regular functioning mode after a brief spike in the load pattern.
* **Actions:** Select one or multiple actions upon alarm trigger.

4. Select **Create** to save the alarm.

{% hint style="success" %}
**Result:** Your alarm will be created; you can edit or delete the alarm configuration if it is no longer needed.‌
{% endhint %}

{% hint style="info" %}
**Note:** The **Status and History** provides an option to list the status and history of an alarm's state transition.‌
{% endhint %}

Upon alarm trigger, the alarm icon will blink to indicate that the configured threshold has been triggered. The blinking will stop automatically once the system is back within the threshold. This is monitored within the defined duration. The alarm status is **OK** while the system runs within the boundaries of the threshold. Once it is outside the boundaries and meets the criteria for triggering an action, the status will change from **OK** to **FIRING**. This transition will execute the defined action. When the system returns to the defined threshold boundaries, the status returns from **FIRING** to **OK**. The status change will be visible in the alarm manager but will not trigger an action.

### Example of an alarm configuration with an alarm delay

The alarm configuration defines an average CPU utilization of 70% or higher as critical, and it has a defined range of two minutes and an alarm delay of zero seconds. The system collects four samples in two minutes in the following example, even though it collects metrics more often.

* Sample01: 20% CPU utilization
* Sample02: 30% CPU utilization
* Sample03: 50% CPU utilization
* Sample04: 70% CPU utilization

The alarm will not trigger for this two-minute range because the average of samples for the considered range will be below 70%. Considering subsequent samples:

* Sample05: 71% CPU utilization
* Sample06: 72% CPU utilization
* Sample07: 75% CPU utilization
* Sample08: 30% CPU utilization

When it reaches **Sample07**, the monitoring service will calculate an average CPU utilization above 70%. As the alarm delay is set to zero seconds, it will trigger an action immediately to send an alarm.

Assume the same example but with an alarm delay of 30 seconds. For **Sample07**, the monitoring service calculates an average CPU utilization above 70%. Still, the system does not trigger an action this time, as an alarm delay of another 60 seconds is configured, but the monitoring system constantly collects further metrics. When it receives **Sample08**, the monitoring services have calculated the average CPU utilization for the previous 120 seconds, which will be below 70%. The system does not trigger an action as the alarm threshold criteria are unfulfilled.

### Configure Alarms

The examples below show possible configurations for the `expression` property of an Alarm.

### Current CPU load for all cores

Setting a trigger when the average load of all cores over the last hour exceeds 90%.

```
"expression": {
  "metric": 
    "instance_cpu_utilization_average",
  "source": {
    "uuid": "279565bf-...-e9572e185144"
  },
  "range": "1h",
  "comparisonThreshold": "90"
}
```

| **Default Values**                                         |
| ---------------------------------------------------------- |
| `unit`: `total`                                            |
| `rangeAggregation`: `average`                              |
| `comparisonOperator`: `greater_than_or_equal_to_threshold` |

### Increase in received bytes

Setting a trigger when more than 1MB is incoming within the last ten minutes.

```
"expression": {
  "metric": "instance_network_in_bytes",
  "source": {
    "uuid": "e17f01e9-...-40968fbbb559"
  },
  "range": "10m",
  "rangeAggregation": "delta",
  "comparisonThreshold": "1000000"
}
```

| **Default Values**                                         |
| ---------------------------------------------------------- |
| `unit`: `totaL`                                            |
| `comparisonOperator`: `greater_than_or_equal_to_threshold` |

### Sent packets per second (lower bound)

Set a trigger if the outgoing packet is less than one per second.

```
"expression": {
  "metric": 
    "instance_network_out_packets",
  "source": {
    "uuid": "e17f01e9-...-40968fbbb559"
  },
  "unit": "per_second",
  "comparisonThreshold": "1",
  "comparisonOperator": 
    "less_than_threshold"
}
```

| **Default Values**            |
| ----------------------------- |
| `range`: `4m`                 |
| `rangeAggregation`: `average` |

### Storage writes per second

Set a trigger if the write operations are more than 100 per second.

```
"expression": {
  "metric": 
    "instance_volumes_write_ops",
  "source": {
    "uuid": "e17f01e9-...-40968fbbb559"
  },
  "unit": "per_second",
  "comparisonThreshold": "100"
}
```

| **Default Values**                                         |
| ---------------------------------------------------------- |
| `unit`: `total`                                            |
| `rangeAggregation`: `average`                              |
| `comparisonOperator`: `greater_than_or_equal_to_threshold` |

## Create an Action

In the **Actions** section, you can configure an action that will be executed when an alarm is activated. Currently, MaaS supports email notifications.

{% hint style="info" %}
**Prerequisite:** Make sure your account has **Monitoring** [<mark style="color:blue;">privileges</mark>](https://docs.ionos.com/sections-test/guides/observability/monitoring-as-a-service/user-permissions#set-user-privileges) enabled in the user group.‌
{% endhint %}

1. In the **DCD**, go to the **Menu** > **Management** > **Monitoring**.
2. In the **Monitoring Manager**‌, select **Create** in the **Actions** tab.
3. A drop-down list will open up. Enter the following values to create an action:‌

* Enter a **Name** for the action.
* Select the **Action type**. We only support **Send Email** at the moment.
* Enter an **Email address**.

4. Select **Create**.

{% hint style="success" %}
**Result:** Your action will be configured and executed when an alarm is activated.
{% endhint %}

{% hint style="info" %}
**Note:** Once an alarm is created, you can edit the action configuration or delete it if it is not needed anymore. You can only delete an action by an alarm when it is not in use. The **Execution History** provides a detailed view of a created action for an executed alarm.
{% endhint %}
