> For the complete documentation index, see [llms.txt](https://docs.datasentinel.io/manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datasentinel.io/manual/features/key-features/alerting/templates.md).

# Templates

A notification template holds the alerting rules and the instances they apply to. Define templates once alerting is enabled on the platform.

A notification template has two parts:

* **Filters**: the [tags](https://docs.datasentinel.io/manual/features/tips-and-hints/tags.md) that select one or more instances.
* **Rules**: the thresholds that decide when a problem is raised.

Templates are assigned at runtime. Each time the metrics of an instance are evaluated, Datasentinel looks for the template matching its tags.

## Filters

Start by choosing one or more filters.

The example below creates a template for all the instances sharing the tag **datacenter=dc1**.

<figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2FaPAsXB45Cf99f4fE2l9s%2Frule_filters.gif?alt=media&amp;token=f34c64ef-bd7d-457e-b881-65924538c11a" alt=""><figcaption><p>Adding filters</p></figcaption></figure>

{% hint style="info" %}
A new instance gets this template automatically if it has the same tag.
{% endhint %}

When several templates match an instance, Datasentinel picks one in this order:

1. A template that names the instance directly in its filters always wins.
2. Otherwise, the most recent matching template is used.

## Rules

Each rule has a WARNING threshold and a CRITICAL threshold. Most rules also have a number of **occurrences**.

Rules are evaluated every minute, so one occurrence is one minute. With 5 occurrences, a problem is raised when the threshold has been exceeded for 5 consecutive minutes. This avoids notifications on short peaks.

### PostgreSQL metrics

| Rule                   | Checks                                      | Unit    | Default WARNING | Default CRITICAL | Default occurrences |
| ---------------------- | ------------------------------------------- | ------- | --------------- | ---------------- | ------------------- |
| Instance status        | Instance unavailable                        | seconds | 60              | 60               |                     |
| Max connections        | Connections used, against `max_connections` | %       | 80              | 95               | 1                   |
| Blocked sessions       | Time sessions have been blocked             | seconds | 60              | 900              | 1                   |
| Sessions consuming CPU | Number of sessions active on CPU            | count   | 10              | 30               | 5                   |
| WAL files              | Number of WAL files                         | count   | 40              | 80               | 1                   |
| WAL file system        | Space used on the WAL file system           | %       | 80              | 95               | 5                   |
| Old archived time      | Delay since the last archived WAL file      | seconds | 3600            | 7200             | 1                   |
| Failed archived files  | Failed WAL archiving attempts               | count   | 10              | 30               | 1                   |
| Replication lag        | Lag of a standby server                     | seconds | 3600            | 7200             | 1                   |

### System metrics

| Rule         | Checks                                            | Unit     | Default WARNING | Default CRITICAL | Default occurrences |
| ------------ | ------------------------------------------------- | -------- | --------------- | ---------------- | ------------------- |
| CPU usage    | CPU used on the server                            | %        | 80              | 95               | 5                   |
| Load average | Load average, as a multiple of the number of CPUs | multiple | 2               | 5                | 5                   |
| Memory usage | Memory used on the server                         | %        | 80              | 95               | 5                   |
| Swap usage   | Swap used on the server                           | %        | 80              | 95               | 5                   |
| File systems | Space used, for each file system                  | %        | 80              | 95               | 5                   |

{% hint style="info" %}
Each rule can be turned on or off.

When the WARNING and CRITICAL values are equal, only CRITICAL problems are raised.

A template is active as soon as it is saved.
{% endhint %}

<figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2FlPNoDot9pD7UAP8yT0cq%2Fpostgresql-rules.png?alt=media&amp;token=990a0889-ee36-4fcc-a800-c1023c27c91c" alt=""><figcaption><p>Rules</p></figcaption></figure>

## Next step

To suspend alerting during maintenance, see [Silences](https://docs.datasentinel.io/manual/features/key-features/alerting/silences.md). To follow the problems, see the [Manager](https://docs.datasentinel.io/manual/features/key-features/alerting/manager.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.datasentinel.io/manual/features/key-features/alerting/templates.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
