VictoriaMetrics/docs/operator/resources/vmrule.md
Github Actions 015f0b0424
Automatic update operator docs from VictoriaMetrics/operator@64879fb (#6831)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: f41gh7 <nik@victoriametrics.com>
2024-08-16 16:32:25 +02:00

3.4 KiB

weight title menu aliases
10 VMRule
docs
identifier parent weight
operator-cr-vmrule operator-cr 10
/operator/resources/vmrule/
/operator/resources/vmrule/index.html

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/operator/resources/vmalert#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: vmrule_recording_groupname
      interval: 1m
      rules:
        - record: vm_http_request_errors_total:sum_by_cluster_namespace_job:rate:5m
          expr: |-
            sum by (cluster, namespace, job) (
              rate(vm_http_request_errors_total[5m])
            )