2023-10-05 10:43:28 +00:00
|
|
|
---
|
|
|
|
weight: 10
|
|
|
|
title: VMRule
|
|
|
|
menu:
|
|
|
|
docs:
|
2024-08-16 14:32:25 +00:00
|
|
|
identifier: operator-cr-vmrule
|
|
|
|
parent: operator-cr
|
2023-10-05 10:43:28 +00:00
|
|
|
weight: 10
|
2023-11-22 11:59:07 +00:00
|
|
|
aliases:
|
2024-08-16 14:32:25 +00:00
|
|
|
- /operator/resources/vmrule/
|
|
|
|
- /operator/resources/vmrule/index.html
|
2023-10-05 10:43:28 +00:00
|
|
|
---
|
2023-10-02 12:50:08 +00:00
|
|
|
`VMRule` represents [alerting](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/)
|
|
|
|
or [recording](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/) rules
|
2024-08-16 14:32:25 +00:00
|
|
|
for [VMAlert](https://docs.victoriametrics.com/operator/resources/vmalert) instances.
|
2023-10-02 12:50:08 +00:00
|
|
|
|
|
|
|
The `VMRule` CRD declaratively defines a desired Prometheus rule to be consumed by one or more VMAlert instances.
|
|
|
|
|
2024-08-16 14:32:25 +00:00
|
|
|
`VMRule` object generates [VMAlert](https://docs.victoriametrics.com/operator/resources/vmalert)
|
2023-10-02 12:50:08 +00:00
|
|
|
with ruleset defined at `VMRule` spec.
|
|
|
|
|
|
|
|
Alerts and recording rules can be saved and applied as YAML files, and dynamically loaded without requiring any restart.
|
|
|
|
|
2024-08-16 14:32:25 +00:00
|
|
|
See more details about rule configuration in [VMAlert docs](https://docs.victoriametrics.com/vmalert#quickstart).
|
2023-10-02 12:50:08 +00:00
|
|
|
|
|
|
|
## Specification
|
|
|
|
|
|
|
|
You can see the full actual specification of the `VMRule` resource in
|
2024-08-16 14:32:25 +00:00
|
|
|
the **[API docs -> VMRule](https://docs.victoriametrics.com/operator/api#vmrule)**.
|
2023-10-02 12:50:08 +00:00
|
|
|
|
|
|
|
Also, you can check out the [examples](#examples) section.
|
|
|
|
|
|
|
|
## Enterprise features
|
|
|
|
|
2024-08-16 14:32:25 +00:00
|
|
|
Custom resource `VMRule` supports feature [Multitenancy](https://docs.victoriametrics.com/vmalert#multitenancy)
|
|
|
|
from [VictoriaMetrics Enterprise](https://docs.victoriametrics.com/enterprise#victoriametrics-enterprise).
|
2023-10-02 12:50:08 +00:00
|
|
|
|
|
|
|
### Multitenancy
|
|
|
|
|
2024-08-16 14:32:25 +00:00
|
|
|
For using [Multitenancy](https://docs.victoriametrics.com/vmalert#multitenancy) in `VMRule`
|
|
|
|
you need to **[enable VMAlert Enterprise](https://docs.victoriametrics.com/operator/resources/vmalert#enterprise-features)**.
|
2023-10-02 12:50:08 +00:00
|
|
|
|
|
|
|
After that you can add `tenant` field for groups in `VMRule`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apiVersion: operator.victoriametrics.com/v1beta1
|
|
|
|
kind: VMRule
|
|
|
|
metadata:
|
|
|
|
name: vmrule-ent-example
|
|
|
|
spec:
|
|
|
|
groups:
|
|
|
|
- name: vmalert-1
|
|
|
|
rules:
|
|
|
|
# using enterprise features: Multitenancy
|
2024-08-16 14:32:25 +00:00
|
|
|
# more details about multitenancy you can read on https://docs.victoriametrics.com/operator/resources/vmalert#multitenancy
|
2023-10-02 12:50:08 +00:00
|
|
|
- tenant: 1
|
|
|
|
alert: vmalert config reload error
|
|
|
|
expr: delta(vmalert_config_last_reload_errors_total[5m]) > 0
|
|
|
|
for: 10s
|
|
|
|
labels:
|
|
|
|
severity: major
|
|
|
|
job: "{{ $labels.job }}"
|
|
|
|
annotations:
|
|
|
|
value: "{{ $value }}"
|
|
|
|
description: 'error reloading vmalert config, reload count for 5 min {{ $value }}'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Alerting rule
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apiVersion: operator.victoriametrics.com/v1beta1
|
|
|
|
kind: VMRule
|
|
|
|
metadata:
|
|
|
|
name: vmrule-alerting-example
|
|
|
|
spec:
|
|
|
|
groups:
|
|
|
|
- name: vmalert
|
|
|
|
rules:
|
|
|
|
- alert: vmalert config reload error
|
|
|
|
expr: delta(vmalert_config_last_reload_errors_total[5m]) > 0
|
|
|
|
for: 10s
|
|
|
|
labels:
|
|
|
|
severity: major
|
|
|
|
job: "{{ $labels.job }}"
|
|
|
|
annotations:
|
|
|
|
value: "{{ $value }}"
|
|
|
|
description: 'error reloading vmalert config, reload count for 5 min {{ $value }}'
|
|
|
|
```
|
|
|
|
|
|
|
|
### Recording rule
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apiVersion: operator.victoriametrics.com/v1beta1
|
|
|
|
kind: VMRule
|
|
|
|
metadata:
|
|
|
|
name: vmrule-recording-example
|
|
|
|
spec:
|
|
|
|
groups:
|
2023-11-28 15:50:24 +00:00
|
|
|
- name: vmrule_recording_groupname
|
2023-10-02 12:50:08 +00:00
|
|
|
interval: 1m
|
|
|
|
rules:
|
2023-11-28 15:50:24 +00:00
|
|
|
- record: vm_http_request_errors_total:sum_by_cluster_namespace_job:rate:5m
|
2023-10-02 12:50:08 +00:00
|
|
|
expr: |-
|
|
|
|
sum by (cluster, namespace, job) (
|
|
|
|
rate(vm_http_request_errors_total[5m])
|
|
|
|
)
|
|
|
|
```
|