vmalert
Available from v1.106.0
integrates with VictoriaLogs
Available from v0.36.0
via stats APIs /select/logsql/stats_query
and /select/logsql/stats_query_range
.
These endpoints return the log stats in a format compatible with Prometheus querying API.
It allows using VictoriaLogs as the datasource in vmalert, creating alerting and recording rules via LogsQL.
Note: This page provides only integration instructions for vmalert and VictoriaLogs. See the full textbook for vmalert here.
Quick Start #
Run vmalert with the following settings:
|
|
Note: By default, vmalert assumes all configured rules have
prometheus
type and will validate them accordingly. For rules in LogsQL specifytype: vlogs
on Group level. Or set-rule.defaultRuleType=vlogs
cmd-line flag to applytype: vlogs
to all configured groups.
Each -rule
file may contain arbitrary number of groups.
See examples in Groups section. See the full list of configuration flags and their descriptions in configuration section.
With configuration example above, vmalert will perform the following interactions:
- Rules listed in
-rule
file are executed against VictoriaLogs service configured via-datasource.url
; - Triggered alerting notifications are sent to Alertmanager service configured via
-notifier.url
; - Results of recording rules expressions and alerts state are persisted to Prometheus-compatible remote-write endpoint
(i.e. VictoriaMetrics) configured via
-remoteWrite.url
; - On vmalert restarts, alerts state can be restored
by querying Prometheus-compatible HTTP API endpoint (i.e. VictoriaMetrics) configured via
-remoteRead.url
.
Configuration #
Flags #
For a complete list of command-line flags, visit https://docs.victoriametrics.com/vmalert/#flags or execute ./vmalert --help
command.
The following are key flags related to integration with VictoriaLogs:
|
|
See full list of configuration options here.
Groups #
Check the complete group attributes here.
Alerting rules #
Examples:
|
|
Recording rules #
Examples:
|
|
Time filter #
It’s recommended to omit the time filter in rule expression.
By default, vmalert automatically appends the time filter _time: <group_interval>
to the expression.
For instance, the rule below will be evaluated every 5 minutes, and will return the result with logs from the last 5 minutes:
|
|
User can specify a customized time filter if needed. For example, rule below will be evaluated every 5 minutes, but will calculate result over the logs from the last 10 minutes.
|
|
Please note, vmalert doesn’t support backfilling for rules with a customized time filter now. (Might be added in future).
Rules backfilling #
vmalert supports alerting and recording rules backfilling (aka replay) against VictoriaLogs as the datasource.
|
|
See more details about backfilling here.
Performance tip #
LogsQL allows users to obtain multiple stats from a single expression. For instance, the following query calculates
50th, 90th and 99th percentiles for the request_duration_seconds
field over logs for the last 5 minutes:
|
|
This expression can also be used in recording rules as follows:
|
|
This creates three metrics for each service:
|
|
For additional tips on writing LogsQL, refer to this doc.
Frequently Asked Questions #
How to use multitenancy in rules? #
vmalert doesn’t support multi-tenancy for VictoriaLogs in the same way as it supports it for VictoriaMetrics in ENT version.
However, it is possible to specify the queried tenant from VictoriaLogs datasource via headers
param in Group config.
For example, the following config will execute all the rules within the group against tenant with AccountID=1
and ProjectID=2
:
|
|
By default, vmalert persists all results to the specific tenant in VictoriaMetrics that specified by -remotewrite.url
. For example, if the -remotewrite.url=http://vminsert:8480/insert/0/prometheus/
, all data goes to tenant 0
.
To persist different rule results to different tenants in VictoriaMetrics, there are following approaches:
To use the multitenant endpoint of vminsert as the
-remoteWrite.url
, and add tenant labels under the group configuration.For example, run vmalert with:
1
./bin/vmalert -datasource.url=http://localhost:9428 -remoteWrite.url=http://vminsert:8480/insert/multitenant/prometheus ...
With the rules below,
recordingTenant123
will be queried from VictoriaLogs tenant123
and persisted to tenant123
in VictoriaMetrics, whilerecordingTenant123-456:789
will be queried from VictoriaLogs tenant124
and persisted to tenant456:789
in VictoriaMetrics.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
groups: - name: recordingTenant123 type: vlogs headers: - "AccountID: 123" labels: vm_account_id: 123 rules: - record: recordingTenant123 expr: 'tags.path:/var/log/httpd OR tags.path:/var/log/nginx | stats by (tags.host) count() requests' - name: recordingTenant124-456:789 type: vlogs headers: - "AccountID: 124" labels: vm_account_id: 456 vm_project_id: 789 rules: - record: recordingTenant124-456:789 expr: 'tags.path:/var/log/httpd OR tags.path:/var/log/nginx | stats by (tags.host) count() requests'
To run enterprise version of vmalert with
-clusterMode
enabled, and specify tenant parameter per each group.For example, run vmalert with:
1
./bin/vmalert -datasource.url=http://localhost:9428 -clusterMode=true -remoteWrite.url=http://vminsert:8480/ ...
With the rules below,
recordingTenant123
will be queried from VictoriaLogs tenant123
and persisted to tenant123
in VictoriaMetrics, whilerecordingTenant123-456:789
will be queried from VictoriaLogs tenant124
and persisted to tenant456:789
in VictoriaMetrics.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
groups: - name: recordingTenant123 type: vlogs headers: - "AccountID: 123" tenant: "123" rules: - record: recordingTenant123 expr: 'tags.path:/var/log/httpd OR tags.path:/var/log/nginx | stats by (tags.host) count() requests' - name: recordingTenant124-456:789 type: vlogs headers: - "AccountID: 124" tenant: "456:789" rules: - record: recordingTenant124-456:789 expr: 'tags.path:/var/log/httpd OR tags.path:/var/log/nginx | stats by (tags.host) count() requests'
How to use one vmalert for VictoriaLogs and VictoriaMetrics rules in the same time? #
We recommend running separate instances of vmalert for VictoriaMetrics and VictoriaLogs.
However, vmalert allows having many groups with different rule types (vlogs
, prometheus
, graphite
).
But only one -datasource.url
cmd-line flag can be specified, so it can’t be configured with more than 1 datasource.
VictoriaMetrics and VictoriaLogs datasources have different query path prefixes, so it is possible to use
vmauth to route requests of different types between datasources.
See example of vmauth config for such routing below:
|
|
Now, vmalert can be configured with --datasource.url=http://vmauth:8427/
to send queries to vmauth,
and vmauth will route them to the specified destinations as in configuration example above.