How to set up alerting based on metrics

vmalert, Alertmanager, rule groups, notification channels.

Overview

Alerting in the Shturval platform is implemented based on Victoria Metrics AlertManager and AlertManagerConfig. Components used:

  • vmalert (VM Alert) - evaluation of alerting rules based on metrics;
  • Alertmanager - routing and delivery of notifications.

By default, alerts are displayed in the platform GUI. Recipients and routes are configured for sending to Email, Telegram, Webhook, etc.


Operating conditions for alerting

Client cluster

Alerting is available from the GUI if enabled:

  • in management cluster: shturval-monitoring and shturval-metrics-collector;
  • in client cluster: shturval-metrics-collector.

Management Cluster

Alerting is configured if the following are enabled:

  • shturval-monitoring in the management cluster;
  • shturval-metrics-collector in the management cluster.

View alerts

Alerts page → View alerts (or the “Alerts” block on the cluster dashboard).

Alerts interface

Alerts

Alerts are divided into tabs:

StatusDescription
FiringThe alert is triggered—an actual violation of a condition or event.
PendingThe alert condition is met but the wait period (for) has not elapsed yet in the future (temporary changes).
InactiveThe alert has not been triggered for a long time or has been disabled by the administrator.

On each tab, alerts are grouped by rule groups. In the group: expression, description of conditions, event counter, list of alerts.

Composition of the alert: identifier, name, date and time of activation, description, expression, criticality.


Predefined rules

Alert rules are installed in clusters by default (VMRule with the prefix system). List available:

  • on the Alert Rules page of the cluster;
  • in Administration → Custom Resources → API group operator.victoriametrics.com → VMRule in the namespace with the cluster name.

Predefined rules cover: Alertmanager, Velero, Victoria Metrics, Kubernetes (nodes, pods, PVC, services), Prometheus, etc.


Alert rule groups

For custom rules, a rule group is created.

  1. Notification rules → Add group of notification rules.
  2. Fill in:
    • Group name (required);
    • Expression type — Prometheus or Graphite (Prometheus by default);
    • Rule type - alert or record;
    • Evaluation interval—how often the rules are evaluated;
    • Parallelism - how many rules run simultaneously in a group.
Alert rule groups

Rule groups

Once created, the group name, expression type, and rule type are immutable. Deleting a group results in a cascade deletion of rules.


Group rules

Under the group summary, the Rules table spans the full width: name, severity (None if not set), and short description (a dash if empty). A row opens the rule, + opens the add form on the right. After adding, the form closes.

Alert rules

FieldDescription
NameRequired and cannot be changed once created.
Wait timeTime lag before sending - the system waits to see if the state will be preserved.
CriticalityRecorded in the label severity. Levels: Emergency, Alert, Critical, Error, Warning, Notice, Info, Debug.
Link to solutionAbstract runbook_url.
Short descriptionAbstract summary.
DescriptionAbstract description.
ExpressionMandatory. PromQL expression.
Labels, annotationsAdditional metadata. How to add and change them: Labels and annotations.

Annotations with keys description, summary, runbook_url are overwritten with values from the rule fields.

Example rule - triggered when a new Pod is created:

sum by(namespace, pod) (increase(kube_pod_created[5m])) > 0

With descriptions: summary: "New pod created in {{ $labels.namespace }}", description: "Pod {{ $labels.pod }} was created in namespace {{ $labels.namespace }}".

Record rules

Expressions are pre-calculated and the result is stored as a time series. Useful for dashboards.

Fields: Title (required), Expression (required), Labels.


Receivers

By default, alerts are routed to Victoria Metrics (displayed in the GUI). The recipient devnull (default type) is created by default and blocks sending; it cannot be deleted or changed.

For additional delivery, recipients are created in the Notifications → Recipients section:

Notification recipients

Recipients

TypePurpose
webhookSending to aggregation services, service-desk, task-manager. Required: URL.
emailSMTP. Required: SMTP server, recipient’s e-mail. Gmail requires authorization.
telegramTelegram bot. Bot token (from @BotFather), chat ID.

Webhook: URL, optional - authorization (Username/Password or Bearer token), TLS, “Send resolved”, max. number of alerts in the message.

Email: SMTP server, recipient’s e-mail, optional - authorization (PLAIN, LOGIN, CRAM-MD5), HTML template, “Send resolved”. Ports 25, 587, 465 must be available on the SMTP side.

Telegram: bot token, chat ID (find out: https://t.me/userinfobot), message format (Markdown, HTML), template, “Send resolved”, “Disable notifications”.


Routes

Routes specify where and under what conditions alerts are sent. The root route is configured first, then the sub-routes.

Route parameters:

ParameterDescription
RecipientSelect from a list of recipients.
Wait time before initial dispatchLag for rejecting false positives.
Wait time until updated alertsLag before sending changes based on a previously sent notification.
Wait time before resendingLag before resending.
Matching LabelsLabels for routing (for example, severity, alertname).
Grouping KeysBy what labels to group notifications.
Blocking IntervalsWhen to pause sending (weekends, nights, etc.).

Sub-routes provide more detailed routing. You can specify whether to continue processing in other subroutes.


Time intervals (time_intervals)

Intervals when alerts are not sent (silencing).

Configurable: months, days of the month, days of the week, hour ranges. Intervals are indicated in the routes.

If no value is specified in the configuration, “all values” is equivalent. For example, only days of the week are selected without months - these days are applied in each month.


Blocking notifications (inhibit)

Criteria under which notifications are blocked (not sent).

ParameterDescription
Label keys (equal)Alert keys: alertname, severity, namespace, etc.
target_matchersTarget alert labels; when they match, related alerts may be suppressed.
source_matchersSource alert labels; while a matching source alert is active, target alerts are not sent.

Example: block Warning if there is a Critical with the same alertname and namespace.


  1. Make sure shturval-monitoring and shturval-metrics-collector are working.
  2. If necessary, create a rule group and add rules (alert or record).
  3. Create recipients (Email, Telegram, Webhook).
  4. Configure routes - specify the recipient, labels, blocking intervals.
  5. If necessary, set time intervals and notification blocking.

Additional

  • Rules can be added via ShturvalServicePatch or the shturval-metrics-collector service configuration.
  • VictoriaMetrics Operator supports importing AlertmanagerConfig from Prometheus Operator.
  • Architecture details: Monitoring services architecture.