VictoriaMetrics/docs/operator/resources/vmrule.md
Artem Navoiev 12b0e3e5cb
add hugo front matter for operator docs (#5122)
Signed-off-by: Artem Navoiev <tenmozes@gmail.com>
2023-10-04 16:28:23 +02:00

3.1 KiB

sort weight title menu
10 10 VMRule
docs
parent weight
operator-custom-resources 10

VMRule

VMRule represents alerting or recording rules for VMAlert instances.

The VMRule CRD declaratively defines a desired Prometheus rule to be consumed by one or more VMAlert instances.

VMRule object generates VMAlert 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.

See more details about rule configuration in VMAlert docs.

Specification

You can see the full actual specification of the VMRule resource in the API docs -> VMRule.

Also, you can check out the examples section.

Enterprise features

Custom resource VMRule supports feature Multitenancy from VictoriaMetrics Enterprise.

Multitenancy

For using Multitenancy in VMRule you need to enable VMAlert Enterprise.

After that you can add tenant field for groups in VMRule:

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: vmrule-ent-example
spec:
  groups:
    - name: vmalert-1
      rules:
        # using enterprise features: Multitenancy
        # more details about multitenancy you can read on https://docs.victoriametrics.com/vmalert.html#multitenancy
        - 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

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

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: vmrule-recording-example
spec:
  groups:
    - name: vmalert
      interval: 1m
      rules:
        - alert: vmalert config reload error
          expr: |-
            sum by (cluster, namespace, job) (
              rate(vm_http_request_errors_total[5m])
            )