2021-04-07 10:39:16 +00:00
# vmalert
2020-02-02 10:14:09 +00:00
2021-06-11 10:25:53 +00:00
`vmalert` executes a list of the given [alerting ](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ )
2020-06-01 10:46:37 +00:00
or [recording ](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/ )
2021-06-11 10:25:53 +00:00
rules against configured address. It is heavily inspired by [Prometheus ](https://prometheus.io/docs/alerting/latest/overview/ )
implementation and aims to be compatible with its syntax.
2020-02-02 10:14:09 +00:00
2021-04-07 10:39:16 +00:00
## Features
2020-04-12 11:47:26 +00:00
* Integration with [VictoriaMetrics ](https://github.com/VictoriaMetrics/VictoriaMetrics ) TSDB;
2021-04-20 17:16:17 +00:00
* VictoriaMetrics [MetricsQL ](https://docs.victoriametrics.com/MetricsQL.html )
2020-06-01 10:46:37 +00:00
support and expressions validation;
2020-04-12 11:47:26 +00:00
* Prometheus [alerting rules definition format ](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#defining-alerting-rules )
support;
* Integration with [Alertmanager ](https://github.com/prometheus/alertmanager );
2021-04-20 17:16:17 +00:00
* Keeps the alerts [state on restarts ](#alerts-state-on-restarts );
2021-06-09 09:27:31 +00:00
* Graphite datasource can be used for alerting and recording rules. See [these docs ](#graphite );
* Recording and Alerting rules backfilling (aka `replay` ). See [these docs ](#rules-backfilling );
2020-04-12 11:47:26 +00:00
* Lightweight without extra dependencies.
2020-02-02 10:14:09 +00:00
2021-04-07 10:39:16 +00:00
## Limitations
2021-03-09 20:49:50 +00:00
* `vmalert` execute queries against remote datasource which has reliability risks because of network.
2020-06-09 12:21:20 +00:00
It is recommended to configure alerts thresholds and rules expressions with understanding that network request
may fail;
* by default, rules execution is sequential within one group, but persisting of execution results to remote
storage is asynchronous. Hence, user shouldn't rely on recording rules chaining when result of previous
recording rule is reused in next one;
* `vmalert` has no UI, just an API for getting groups and rules statuses.
2021-04-07 10:39:16 +00:00
## QuickStart
2020-02-02 10:14:09 +00:00
2020-04-12 11:47:26 +00:00
To build `vmalert` from sources:
```
git clone https://github.com/VictoriaMetrics/VictoriaMetrics
cd VictoriaMetrics
make vmalert
```
The build binary will be placed to `VictoriaMetrics/bin` folder.
2020-02-02 10:14:09 +00:00
2020-04-12 11:47:26 +00:00
To start using `vmalert` you will need the following things:
2020-06-01 10:46:37 +00:00
* list of rules - PromQL/MetricsQL expressions to execute;
2020-04-12 11:47:26 +00:00
* datasource address - reachable VictoriaMetrics instance for rules execution;
2021-03-09 20:49:50 +00:00
* notifier address - reachable [Alert Manager ](https://github.com/prometheus/alertmanager ) instance for processing,
2020-04-12 11:47:26 +00:00
aggregating alerts and sending notifications.
2021-06-11 10:25:53 +00:00
* remote write address [optional] - [remote write ](https://prometheus.io/docs/prometheus/latest/storage/#remote-storage-integrations )
compatible storage address for storing recording rules results and alerts state in for of timeseries.
2020-02-02 10:14:09 +00:00
2020-04-12 11:47:26 +00:00
Then configure `vmalert` accordingly:
```
2021-06-11 10:25:53 +00:00
./bin/vmalert -rule=alert.rules \ # Path to the file with rules configuration. Supports wildcard
2020-07-28 11:20:31 +00:00
-datasource.url=http://localhost:8428 \ # PromQL compatible datasource
-notifier.url=http://localhost:9093 \ # AlertManager URL
-notifier.url=http://127.0.0.1:9093 \ # AlertManager replica URL
2021-06-11 10:25:53 +00:00
-remoteWrite.url=http://localhost:8428 \ # Remote write compatible storage to persist rules
-remoteRead.url=http://localhost:8428 \ # MetricsQL compatible datasource to restore alerts state from
2020-07-28 11:20:31 +00:00
-external.label=cluster=east-1 \ # External label to be applied for each rule
2021-03-25 13:29:04 +00:00
-external.label=replica=a # Multiple external labels may be set
2020-04-12 11:47:26 +00:00
```
2020-02-02 10:14:09 +00:00
2021-06-11 10:25:53 +00:00
See the fill list of configuration flags in [configuration ](#configuration ) section.
2020-07-28 11:20:31 +00:00
If you run multiple `vmalert` services for the same datastore or AlertManager - do not forget
2021-03-09 20:49:50 +00:00
to specify different `external.label` flags in order to define which `vmalert` generated rules or alerts.
2020-07-28 11:20:31 +00:00
2021-03-09 20:49:50 +00:00
Configuration for [recording ](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/ )
and [alerting ](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ ) rules is very
similar to Prometheus rules and configured using YAML. Configuration examples may be found
2020-06-10 16:26:27 +00:00
in [testdata ](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/config/testdata ) folder.
2021-06-11 10:25:53 +00:00
Every `rule` belongs to a `group` and every configuration file may contain arbitrary number of groups:
2020-06-09 12:21:20 +00:00
```yaml
groups:
[ - < rule_group > ]
```
2020-06-01 10:46:37 +00:00
2021-04-07 10:39:16 +00:00
### Groups
2020-02-02 10:14:09 +00:00
2021-06-11 10:25:53 +00:00
Each group has the following attributes:
2020-06-09 12:21:20 +00:00
```yaml
# The name of the group. Must be unique within a file.
name: < string >
2020-02-02 10:14:09 +00:00
2020-06-09 12:21:20 +00:00
# How often rules in the group are evaluated.
2021-06-11 10:25:53 +00:00
[ interval: < duration > | default = -evaluationInterval flag ]
2020-06-09 12:21:20 +00:00
2021-06-11 10:25:53 +00:00
# How many rules execute at once within a group. Increasing concurrency may speed
2021-03-09 20:49:50 +00:00
# up round execution speed.
2020-06-09 12:21:20 +00:00
[ concurrency: < integer > | default = 1 ]
2021-02-03 19:12:14 +00:00
# Optional type for expressions inside the rules. Supported values: "graphite" and "prometheus".
# By default "prometheus" rule type is used.
[ type: < string > ]
2021-05-22 21:26:01 +00:00
# Optional list of label filters applied to every rule's
# request withing a group. Is compatible only with VM datasource.
# See more details at https://docs.victoriametrics.com#prometheus-querying-api-enhancements
extra_filter_labels:
[ < labelname > : < labelvalue > ... ]
2020-06-09 12:21:20 +00:00
rules:
[ - < rule > ... ]
```
2021-04-07 10:39:16 +00:00
### Rules
2020-06-09 12:21:20 +00:00
2021-06-11 10:25:53 +00:00
Every rule contains `expr` field for [PromQL ](https://prometheus.io/docs/prometheus/latest/querying/basics/ )
or [MetricsQL ](https://docs.victoriametrics.com/MetricsQL.html ) expression. Vmalert will execute the configured
expression and then act according to the Rule type.
2020-06-09 12:21:20 +00:00
There are two types of Rules:
2021-03-09 20:49:50 +00:00
* [alerting ](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ ) -
2021-08-16 11:20:57 +00:00
Alerting rules allows to define alert conditions via `expr` field and to send notifications
2021-06-11 10:25:53 +00:00
[Alertmanager ](https://github.com/prometheus/alertmanager ) if execution result is not empty.
2021-03-09 20:49:50 +00:00
* [recording ](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/ ) -
2021-06-11 10:25:53 +00:00
Recording rules allows to define `expr` which result will be than backfilled to configured
2021-08-16 11:20:57 +00:00
`-remoteWrite.url` . Recording rules are used to precompute frequently needed or computationally
2021-06-11 10:25:53 +00:00
expensive expressions and save their result as a new set of time series.
2020-06-09 12:21:20 +00:00
2020-06-15 19:15:47 +00:00
`vmalert` forbids to define duplicates - rules with the same combination of name, expression and labels
2021-03-09 20:49:50 +00:00
within one group.
2020-06-15 19:15:47 +00:00
2021-04-07 10:39:16 +00:00
#### Alerting rules
2020-06-09 12:21:20 +00:00
2021-06-11 10:25:53 +00:00
The syntax for alerting rule is the following:
2020-06-09 12:21:20 +00:00
```yaml
# The name of the alert. Must be a valid metric name.
alert: < string >
2021-02-01 13:26:33 +00:00
# Optional type for the rule. Supported values: "graphite", "prometheus".
# By default "prometheus" rule type is used.
[ type: < string > ]
# The expression to evaluate. The expression language depends on the type value.
2021-06-11 10:25:53 +00:00
# By default PromQL/MetricsQL expression is used. If type="graphite", then the expression
2021-02-01 13:26:33 +00:00
# must contain valid Graphite expression.
2020-06-09 12:21:20 +00:00
expr: < string >
# Alerts are considered firing once they have been returned for this long.
# Alerts which have not yet fired for long enough are considered pending.
2021-06-11 10:25:53 +00:00
# If param is omitted or set to 0 then alerts will be immediately considered
# as firing once they return.
2020-06-09 12:21:20 +00:00
[ for: < duration > | default = 0s ]
2020-06-01 10:46:37 +00:00
2020-06-09 12:21:20 +00:00
# Labels to add or overwrite for each alert.
labels:
[ < labelname > : < tmpl_string > ]
# Annotations to add to each alert.
annotations:
[ < labelname > : < tmpl_string > ]
2021-03-09 20:49:50 +00:00
```
2020-06-09 12:21:20 +00:00
2021-04-08 15:19:08 +00:00
It is allowed to use [Go templating ](https://golang.org/pkg/text/template/ ) in annotations
to format data, iterate over it or execute expressions.
Additionally, `vmalert` provides some extra templating functions
listed [here ](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/notifier/template_func.go ).
2021-04-07 10:39:16 +00:00
#### Recording rules
2020-06-09 12:21:20 +00:00
The syntax for recording rules is following:
```yaml
# The name of the time series to output to. Must be a valid metric name.
record: < string >
2021-02-01 13:26:33 +00:00
# Optional type for the rule. Supported values: "graphite", "prometheus".
# By default "prometheus" rule type is used.
[ type: < string > ]
# The expression to evaluate. The expression language depends on the type value.
# By default MetricsQL expression is used. If type="graphite", then the expression
# must contain valid Graphite expression.
2020-06-09 12:21:20 +00:00
expr: < string >
# Labels to add or overwrite before storing the result.
labels:
[ < labelname > : < labelvalue > ]
```
2021-06-11 10:25:53 +00:00
For recording rules to work `-remoteWrite.url` must be specified.
2020-06-09 12:21:20 +00:00
2021-04-07 10:39:16 +00:00
### Alerts state on restarts
2020-10-13 15:32:43 +00:00
2021-06-11 10:25:53 +00:00
`vmalert` has no local storage, so alerts state is stored in the process memory. Hence, after restart of `vmalert`
2020-10-13 15:32:43 +00:00
the process alerts state will be lost. To avoid this situation, `vmalert` should be configured via the following flags:
2021-04-20 08:42:17 +00:00
* `-remoteWrite.url` - URL to VictoriaMetrics (Single) or vminsert (Cluster). `vmalert` will persist alerts state
2021-03-09 20:49:50 +00:00
into the configured address in the form of time series named `ALERTS` and `ALERTS_FOR_STATE` via remote-write protocol.
These are regular time series and may be queried from VM just as any other time series.
2020-10-13 15:32:43 +00:00
The state stored to the configured address on every rule evaluation.
2021-04-20 08:42:17 +00:00
* `-remoteRead.url` - URL to VictoriaMetrics (Single) or vmselect (Cluster). `vmalert` will try to restore alerts state
2020-10-13 15:32:43 +00:00
from configured address by querying time series with name `ALERTS_FOR_STATE` .
Both flags are required for the proper state restoring. Restore process may fail if time series are missing
2021-08-16 11:20:57 +00:00
in configured `-remoteRead.url` , weren't updated in the last `1h` (controlled by `-remoteRead.lookback` )
2021-06-11 10:25:53 +00:00
or received state doesn't match current `vmalert` rules configuration.
2020-10-13 15:32:43 +00:00
2021-05-18 13:22:08 +00:00
### Multitenancy
2021-08-16 11:20:57 +00:00
There are the following approaches for alerting and recording rules across
2021-06-11 10:25:53 +00:00
[multiple tenants ](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#multitenancy ):
2021-05-18 13:22:08 +00:00
2021-08-16 11:20:57 +00:00
* To run a separate `vmalert` instance per each tenant.
The corresponding tenant must be specified in `-datasource.url` command-line flag
according to [these docs ](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#url-format ).
2021-06-11 10:25:53 +00:00
For example, `/path/to/vmalert -datasource.url=http://vmselect:8481/select/123/prometheus`
2021-08-16 11:20:57 +00:00
would run alerts against `AccountID=123` . For recording rules the `-remoteWrite.url` command-line
flag must contain the url for the specific tenant as well.
For example, `-remoteWrite.url=http://vminsert:8480/insert/123/prometheus` would write recording
2021-06-11 10:25:53 +00:00
rules to `AccountID=123` .
2021-05-18 13:22:08 +00:00
2021-08-16 11:20:57 +00:00
* To specify `tenant` parameter per each alerting and recording group if
[enterprise version of vmalert ](https://victoriametrics.com/enterprise.html ) is used
2021-06-11 10:25:53 +00:00
with `-clusterMode` command-line flag. For example:
2021-05-18 13:22:08 +00:00
```yaml
groups:
- name: rules_for_tenant_123
tenant: "123"
rules:
# Rules for accountID=123
- name: rules_for_tenant_456:789
tenant: "456:789"
rules:
# Rules for accountID=456, projectID=789
```
2021-08-16 11:20:57 +00:00
If `-clusterMode` is enabled, then `-datasource.url` , `-remoteRead.url` and `-remoteWrite.url` must
contain only the hostname without tenant id. For example: `-datasource.url=http://vmselect:8481` .
2021-06-11 10:25:53 +00:00
`vmselect` automatically adds the specified tenant to urls per each recording rule in this case.
2021-05-18 13:22:08 +00:00
2021-08-16 11:20:57 +00:00
The enterprise version of vmalert is available in `vmutils-*-enterprise.tar.gz` files
at [release page ](https://github.com/VictoriaMetrics/VictoriaMetrics/releases ) and in `*-enterprise`
2021-06-11 10:25:53 +00:00
tags at [Docker Hub ](https://hub.docker.com/r/victoriametrics/vmalert/tags ).
2021-05-18 13:22:08 +00:00
2021-04-07 10:39:16 +00:00
### WEB
2020-06-09 12:21:20 +00:00
`vmalert` runs a web-server (`-httpListenAddr`) for serving metrics and alerts endpoints:
2020-06-01 10:46:37 +00:00
* `http://<vmalert-addr>/api/v1/groups` - list of all loaded groups and rules;
2020-04-12 11:47:26 +00:00
* `http://<vmalert-addr>/api/v1/alerts` - list of all active alerts;
2021-03-03 08:42:06 +00:00
* `http://<vmalert-addr>/api/v1/<groupID>/<alertID>/status" ` - get alert status by ID.
2020-04-12 11:47:26 +00:00
Used as alert source in AlertManager.
* `http://<vmalert-addr>/metrics` - application metrics.
2020-05-10 16:58:17 +00:00
* `http://<vmalert-addr>/-/reload` - hot configuration reload.
2020-04-12 11:47:26 +00:00
2020-06-09 12:21:20 +00:00
2021-04-07 10:39:16 +00:00
## Graphite
2021-02-01 13:26:33 +00:00
vmalert sends requests to `<-datasource.url>/render?format=json` during evaluation of alerting and recording rules
2021-02-03 19:12:14 +00:00
if the corresponding group or rule contains `type: "graphite"` config option. It is expected that the `<-datasource.url>/render`
2021-02-01 13:26:33 +00:00
implements [Graphite Render API ](https://graphite.readthedocs.io/en/stable/render_api.html ) for `format=json` .
2021-02-03 21:44:37 +00:00
When using vmalert with both `graphite` and `prometheus` rules configured against cluster version of VM do not forget
to set `-datasource.appendTypePrefix` flag to `true` , so vmalert can adjust URL prefix automatically based on query type.
2021-02-01 13:26:33 +00:00
2021-06-09 09:20:38 +00:00
## Rules backfilling
vmalert supports alerting and recording rules backfilling (aka `replay` ). In replay mode vmalert
can read the same rules configuration as normally, evaluate them on the given time range and backfill
results via remote write to the configured storage. vmalert supports any PromQL/MetricsQL compatible
data source for backfilling.
### How it works
In `replay` mode vmalert works as a cli-tool and exits immediately after work is done.
To run vmalert in `replay` mode:
```
./bin/vmalert -rule=path/to/your.rules \ # path to files with rules you usually use with vmalert
-datasource.url=http://localhost:8428 \ # PromQL/MetricsQL compatible datasource
-remoteWrite.url=http://localhost:8428 \ # remote write compatible storage to persist results
-replay.timeFrom=2021-05-11T07:21:43Z \ # time from begin replay
-replay.timeTo=2021-05-29T18:40:43Z # time to finish replay
```
The output of the command will look like the following:
```
Replay mode:
from: 2021-05-11 07:21:43 +0000 UTC # set by -replay.timeFrom
to: 2021-05-29 18:40:43 +0000 UTC # set by -replay.timeTo
max data points per request: 1000 # set by -replay.maxDatapointsPerQuery
Group "ReplayGroup"
interval: 1m0s
requests to make: 27
max range per request: 16h40m0s
> Rule "type:vm_cache_entries:rate5m" (ID: 1792509946081842725)
27 / 27 [----------------------------------------------------------------------------------------------------] 100.00% 78 p/s
> Rule "go_cgo_calls_count:rate5m" (ID: 17958425467471411582)
27 / 27 [-----------------------------------------------------------------------------------------------------] 100.00% ? p/s
Group "vmsingleReplay"
interval: 30s
requests to make: 54
max range per request: 8h20m0s
> Rule "RequestErrorsToAPI" (ID: 17645863024999990222)
54 / 54 [-----------------------------------------------------------------------------------------------------] 100.00% ? p/s
> Rule "TooManyLogs" (ID: 9042195394653477652)
54 / 54 [-----------------------------------------------------------------------------------------------------] 100.00% ? p/s
2021-06-07T09:59:12.098Z info app/vmalert/replay.go:68 replay finished! Imported 511734 samples
```
In `replay` mode all groups are executed sequentially one-by-one. Rules within the group are
executed sequentially as well (`concurrency` setting is ignored). Vmalert sends rule's expression
to [/query_range ](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries ) endpoint
of the configured `-datasource.url` . Returned data then processed according to the rule type and
backfilled to `-remoteWrite.url` via [Remote Write protocol ](https://prometheus.io/docs/prometheus/latest/storage/#remote-storage-integrations ).
Vmalert respects `evaluationInterval` value set by flag or per-group during the replay.
#### Recording rules
Result of recording rules `replay` should match with results of normal rules evaluation.
#### Alerting rules
Result of alerting rules `replay` is time series reflecting [alert's state ](#alerts-state-on-restarts ).
To see if `replayed` alert has fired in the past use the following PromQL/MetricsQL expression:
```
ALERTS{alertname="your_alertname", alertstate="firing"}
```
Execute the query against storage which was used for `-remoteWrite.url` during the `replay` .
### Additional configuration
There are following non-required `replay` flags:
* `-replay.maxDatapointsPerQuery` - the max number of data points expected to receive in one request.
In two words, it affects the max time range for every `/query_range` request. The higher the value,
the less requests will be issued during `replay` .
* `-replay.ruleRetryAttempts` - when datasource fails to respond vmalert will make this number of retries
per rule before giving up.
* `-replay.rulesDelay` - delay between sequential rules execution. Important in cases if there are chaining
(rules which depend on each other) rules. It is expected, that remote storage will be able to persist
previously accepted data during the delay, so data will be available for the subsequent queries.
Keep it equal or bigger than `-remoteWrite.flushInterval` .
See full description for these flags in `./vmalert --help` .
### Limitations
* Graphite engine isn't supported yet;
* `query` template function is disabled for performance reasons (might be changed in future);
2021-02-01 13:26:33 +00:00
2021-04-07 10:39:16 +00:00
## Configuration
2020-04-12 11:47:26 +00:00
2021-06-11 10:25:53 +00:00
Pass `-help` to `vmalert` in order to see the full list of supported
command-line flags with their descriptions.
2020-04-12 11:47:26 +00:00
The shortlist of configuration flags is the following:
```
2021-02-03 21:44:37 +00:00
-datasource.appendTypePrefix
2021-08-11 07:29:33 +00:00
Whether to add type prefix to -datasource.url based on the query type. Set to true if sending different query types to the vmselect URL.
2020-04-12 11:47:26 +00:00
-datasource.basicAuth.password string
2021-08-11 07:29:33 +00:00
Optional basic auth password for -datasource.url
2020-04-12 11:47:26 +00:00
-datasource.basicAuth.username string
2021-08-11 07:29:33 +00:00
Optional basic auth username for -datasource.url
2020-09-30 06:49:45 +00:00
-datasource.lookback duration
2021-08-11 07:29:33 +00:00
Lookback defines how far into the past to look when evaluating queries. For example, if the datasource.lookback=5m then param "time" with value now()-5m will be added to every query.
2020-09-30 06:49:45 +00:00
-datasource.maxIdleConnections int
2021-08-11 07:29:33 +00:00
Defines the number of idle (keep-alive connections) to each configured datasource. Consider setting this value equal to the value: groups_total * group.concurrency. Too low a value may result in a high number of sockets in TIME_WAIT state. (default 100)
2021-03-01 15:01:27 +00:00
-datasource.queryStep duration
2021-08-11 07:29:33 +00:00
queryStep defines how far a value can fallback to when evaluating queries. For example, if datasource.queryStep=15s then param "step" with value "15s" will be added to every query.If queryStep isn't specified, rule's evaluationInterval will be used instead.
2021-05-10 08:18:26 +00:00
-datasource.roundDigits int
2021-08-11 07:29:33 +00:00
Adds "round_digits" GET param to datasource requests. In VM "round_digits" limits the number of digits after the decimal point in response values.
2020-08-14 16:13:24 +00:00
-datasource.tlsCAFile string
2021-08-11 07:29:33 +00:00
Optional path to TLS CA file to use for verifying connections to -datasource.url. By default, system CA is used
2020-08-14 16:13:24 +00:00
-datasource.tlsCertFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate file to use when connecting to -datasource.url
2020-06-23 19:45:45 +00:00
-datasource.tlsInsecureSkipVerify
2021-08-11 07:29:33 +00:00
Whether to skip tls verification when connecting to -datasource.url
2020-08-14 16:13:24 +00:00
-datasource.tlsKeyFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate key to use when connecting to -datasource.url
2020-08-14 16:13:24 +00:00
-datasource.tlsServerName string
2021-08-11 07:29:33 +00:00
Optional TLS server name to use for connections to -datasource.url. By default, the server name from -datasource.url is used
2020-05-04 21:51:22 +00:00
-datasource.url string
2021-08-11 07:29:33 +00:00
VictoriaMetrics or vmselect url. Required parameter. E.g. http://127.0.0.1:8428
2020-12-22 20:32:10 +00:00
-dryRun -rule
2021-08-11 07:29:33 +00:00
Whether to check only config files without running vmalert. The rules file are validated. The -rule flag must be specified.
2020-08-14 16:13:24 +00:00
-enableTCP6
2021-08-11 07:29:33 +00:00
Whether to enable IPv6 for listening and dialing. By default only IPv4 TCP and UDP is used
2020-08-14 16:13:24 +00:00
-envflag.enable
2021-08-11 07:29:33 +00:00
Whether to enable reading flags from environment variables additionally to command line. Command line flag values have priority over values from environment vars. Flags are read only from command line if this flag isn't set. See https://docs.victoriametrics.com/#environment-variables for more details
2020-08-14 16:13:24 +00:00
-envflag.prefix string
2021-08-11 07:29:33 +00:00
Prefix for environment variables if -envflag.enable is set
2020-04-12 11:47:26 +00:00
-evaluationInterval duration
2021-08-11 07:29:33 +00:00
How often to evaluate the rules (default 1m0s)
2020-08-14 16:13:24 +00:00
-external.alert.source string
2021-08-11 07:29:33 +00:00
External Alert Source allows to override the Source link for alerts sent to AlertManager for cases where you want to build a custom link to Grafana, Prometheus or any other service.
eg. 'explore?orgId=1& left=[\"now-1h\",\"now\",\"VictoriaMetrics\",{\"expr\": \"{{$expr|quotesEscape|crlfEscape|queryEscape}}\"},{\"mode\":\"Metrics\"},{\"ui\":[true,true,true,\"none\"]}]'.If empty '/api/v1/:groupID/alertID/status' is used
2020-07-28 11:20:31 +00:00
-external.label array
2021-08-11 07:29:33 +00:00
Optional label in the form 'name=value' to add to all generated recording rules and alerts. Pass multiple -label flags in order to add multiple label sets.
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-external.url string
2021-08-11 07:29:33 +00:00
External URL is used as alert's source for sent alerts to the notifier
2021-03-01 15:01:27 +00:00
-fs.disableMmap
2021-08-11 07:29:33 +00:00
Whether to use pread() instead of mmap() for reading data files. By default mmap() is used for 64-bit arches and pread() is used for 32-bit arches, since they cannot read data files bigger than 2^32 bytes in memory. mmap() is usually faster for reading small data chunks than pread()
2020-09-09 18:10:34 +00:00
-http.connTimeout duration
2021-08-11 07:29:33 +00:00
Incoming http connections are closed after the configured timeout. This may help to spread the incoming load among a cluster of services behind a load balancer. Please note that the real timeout may be bigger by up to 10% as a protection against the thundering herd problem (default 2m0s)
2020-08-14 16:13:24 +00:00
-http.disableResponseCompression
2021-08-11 07:29:33 +00:00
Disable compression of HTTP responses to save CPU resources. By default compression is enabled to save network bandwidth
2020-09-09 18:10:34 +00:00
-http.idleConnTimeout duration
2021-08-11 07:29:33 +00:00
Timeout for incoming idle http connections (default 1m0s)
2020-08-14 16:13:24 +00:00
-http.maxGracefulShutdownDuration duration
2021-08-11 07:29:33 +00:00
The maximum duration for a graceful shutdown of the HTTP server. A highly loaded server may require increased value for a graceful shutdown (default 7s)
2020-08-14 16:13:24 +00:00
-http.pathPrefix string
2021-08-11 07:29:33 +00:00
An optional prefix to add to all the paths handled by http server. For example, if '-http.pathPrefix=/foo/bar' is set, then all the http requests will be handled on '/foo/bar/*' paths. This may be useful for proxied requests. See https://www.robustperception.io/using-external-urls-and-proxies-with-prometheus
2020-08-14 16:13:24 +00:00
-http.shutdownDelay duration
2021-08-11 07:29:33 +00:00
Optional delay before http server shutdown. During this delay, the server returns non-OK responses from /health page, so load balancers can route new requests to other servers
2020-08-14 16:13:24 +00:00
-httpAuth.password string
2021-08-11 07:29:33 +00:00
Password for HTTP Basic Auth. The authentication is disabled if -httpAuth.username is empty
2020-08-14 16:13:24 +00:00
-httpAuth.username string
2021-08-11 07:29:33 +00:00
Username for HTTP Basic Auth. The authentication is disabled if empty. See also -httpAuth.password
2020-04-27 21:18:02 +00:00
-httpListenAddr string
2021-08-11 07:29:33 +00:00
Address to listen for http connections (default ":8880")
2020-12-22 20:32:10 +00:00
-loggerDisableTimestamps
2021-08-11 07:29:33 +00:00
Whether to disable writing timestamps in logs
2020-08-14 16:13:24 +00:00
-loggerErrorsPerSecondLimit int
2021-08-11 07:29:33 +00:00
Per-second limit on the number of ERROR messages. If more than the given number of errors are emitted per second, the remaining errors are suppressed. Zero values disable the rate limit
2020-08-14 16:13:24 +00:00
-loggerFormat string
2021-08-11 07:29:33 +00:00
Format for logs. Possible values: default, json (default "default")
2020-08-14 16:13:24 +00:00
-loggerLevel string
2021-08-11 07:29:33 +00:00
Minimum level of errors to log. Possible values: INFO, WARN, ERROR, FATAL, PANIC (default "INFO")
2020-08-14 16:13:24 +00:00
-loggerOutput string
2021-08-11 07:29:33 +00:00
Output for the logs. Supported values: stderr, stdout (default "stderr")
2021-03-01 15:01:27 +00:00
-loggerTimezone string
2021-08-11 07:29:33 +00:00
Timezone to use for timestamps in logs. Timezone must be a valid IANA Time Zone. For example: America/New_York, Europe/Berlin, Etc/GMT+3 or Local (default "UTC")
2020-12-22 20:32:10 +00:00
-loggerWarnsPerSecondLimit int
2021-08-11 07:29:33 +00:00
Per-second limit on the number of WARN messages. If more than the given number of warns are emitted per second, then the remaining warns are suppressed. Zero values disable the rate limit
2021-03-15 19:59:25 +00:00
-memory.allowedBytes size
2021-08-11 07:29:33 +00:00
Allowed size of system memory VictoriaMetrics caches may occupy. This option overrides -memory.allowedPercent if set to a non-zero value. Too low a value may increase the cache miss rate usually resulting in higher CPU and disk IO usage. Too high a value may evict too much data from OS page cache resulting in higher disk IO usage
Supports the following optional suffixes for size values: KB, MB, GB, KiB, MiB, GiB (default 0)
2020-08-14 16:13:24 +00:00
-memory.allowedPercent float
2021-08-11 07:29:33 +00:00
Allowed percent of system memory VictoriaMetrics caches may occupy. See also -memory.allowedBytes. Too low a value may increase cache miss rate usually resulting in higher CPU and disk IO usage. Too high a value may evict too much data from OS page cache which will result in higher disk IO usage (default 60)
2020-06-01 10:46:37 +00:00
-metricsAuthKey string
2021-08-11 07:29:33 +00:00
Auth key for /metrics. It overrides httpAuth settings
2020-08-14 16:13:24 +00:00
-notifier.basicAuth.password array
2021-08-11 07:29:33 +00:00
Optional basic auth password for -notifier.url
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.basicAuth.username array
2021-08-11 07:29:33 +00:00
Optional basic auth username for -notifier.url
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.tlsCAFile array
2021-08-11 07:29:33 +00:00
Optional path to TLS CA file to use for verifying connections to -notifier.url. By default system CA is used
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.tlsCertFile array
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate file to use when connecting to -notifier.url
Supports an array of values separated by comma or specified via multiple flags.
2020-12-22 20:32:10 +00:00
-notifier.tlsInsecureSkipVerify array
2021-08-11 07:29:33 +00:00
Whether to skip tls verification when connecting to -notifier.url
Supports array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.tlsKeyFile array
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate key to use when connecting to -notifier.url
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.tlsServerName array
2021-08-11 07:29:33 +00:00
Optional TLS server name to use for connections to -notifier.url. By default the server name from -notifier.url is used
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-notifier.url array
2021-08-11 07:29:33 +00:00
Prometheus alertmanager URL. Required parameter. e.g. http://127.0.0.1:9093
Supports an array of values separated by comma or specified via multiple flags.
2020-08-14 16:13:24 +00:00
-pprofAuthKey string
2021-08-11 07:29:33 +00:00
Auth key for /debug/pprof. It overrides httpAuth settings
2020-05-13 18:32:21 +00:00
-remoteRead.basicAuth.password string
2021-08-11 07:29:33 +00:00
Optional basic auth password for -remoteRead.url
2020-05-13 18:32:21 +00:00
-remoteRead.basicAuth.username string
2021-08-11 07:29:33 +00:00
Optional basic auth username for -remoteRead.url
2021-05-10 08:18:26 +00:00
-remoteRead.ignoreRestoreErrors
2021-08-11 07:29:33 +00:00
Whether to ignore errors from remote storage when restoring alerts state on startup. (default true)
2020-05-13 18:32:21 +00:00
-remoteRead.lookback duration
2021-08-11 07:29:33 +00:00
Lookback defines how far to look into past for alerts timeseries. For example, if lookback=1h then range from now() to now()-1h will be scanned. (default 1h0m0s)
2020-08-14 16:13:24 +00:00
-remoteRead.tlsCAFile string
2021-08-11 07:29:33 +00:00
Optional path to TLS CA file to use for verifying connections to -remoteRead.url. By default system CA is used
2020-08-14 16:13:24 +00:00
-remoteRead.tlsCertFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate file to use when connecting to -remoteRead.url
2020-06-23 19:45:45 +00:00
-remoteRead.tlsInsecureSkipVerify
2021-08-11 07:29:33 +00:00
Whether to skip tls verification when connecting to -remoteRead.url
2020-08-14 16:13:24 +00:00
-remoteRead.tlsKeyFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate key to use when connecting to -remoteRead.url
2020-08-14 16:13:24 +00:00
-remoteRead.tlsServerName string
2021-08-11 07:29:33 +00:00
Optional TLS server name to use for connections to -remoteRead.url. By default the server name from -remoteRead.url is used
2020-05-13 18:32:21 +00:00
-remoteRead.url vmalert
2021-08-11 07:29:33 +00:00
Optional URL to VictoriaMetrics or vmselect that will be used to restore alerts state. This configuration makes sense only if vmalert was configured with `remoteWrite.url` before and has been successfully persisted its state. E.g. http://127.0.0.1:8428
2020-05-13 18:32:21 +00:00
-remoteWrite.basicAuth.password string
2021-08-11 07:29:33 +00:00
Optional basic auth password for -remoteWrite.url
2020-05-13 18:32:21 +00:00
-remoteWrite.basicAuth.username string
2021-08-11 07:29:33 +00:00
Optional basic auth username for -remoteWrite.url
2020-06-01 10:46:37 +00:00
-remoteWrite.concurrency int
2021-08-11 07:29:33 +00:00
Defines number of writers for concurrent writing into remote querier (default 1)
2021-08-16 12:20:22 +00:00
-remoteWrite.disablePathAppend
Whether to disable automatic appending of '/api/v1/write' path to the configured -remoteWrite.url.
2020-06-28 11:26:22 +00:00
-remoteWrite.flushInterval duration
2021-08-11 07:29:33 +00:00
Defines interval of flushes to remote write endpoint (default 5s)
2020-06-01 10:46:37 +00:00
-remoteWrite.maxBatchSize int
2021-08-11 07:29:33 +00:00
Defines defines max number of timeseries to be flushed at once (default 1000)
2020-06-01 10:46:37 +00:00
-remoteWrite.maxQueueSize int
2021-08-11 07:29:33 +00:00
Defines the max number of pending datapoints to remote write endpoint (default 100000)
2020-08-14 16:13:24 +00:00
-remoteWrite.tlsCAFile string
2021-08-11 07:29:33 +00:00
Optional path to TLS CA file to use for verifying connections to -remoteWrite.url. By default system CA is used
2020-08-14 16:13:24 +00:00
-remoteWrite.tlsCertFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate file to use when connecting to -remoteWrite.url
2020-06-23 19:45:45 +00:00
-remoteWrite.tlsInsecureSkipVerify
2021-08-11 07:29:33 +00:00
Whether to skip tls verification when connecting to -remoteWrite.url
2020-08-14 16:13:24 +00:00
-remoteWrite.tlsKeyFile string
2021-08-11 07:29:33 +00:00
Optional path to client-side TLS certificate key to use when connecting to -remoteWrite.url
2020-08-14 16:13:24 +00:00
-remoteWrite.tlsServerName string
2021-08-11 07:29:33 +00:00
Optional TLS server name to use for connections to -remoteWrite.url. By default the server name from -remoteWrite.url is used
2020-05-13 18:32:21 +00:00
-remoteWrite.url string
2021-08-11 07:29:33 +00:00
Optional URL to VictoriaMetrics or vminsert where to persist alerts state and recording rules results in form of timeseries. E.g. http://127.0.0.1:8428
2021-06-09 09:20:38 +00:00
-replay.maxDatapointsPerQuery int
2021-08-11 07:29:33 +00:00
Max number of data points expected in one request. The higher the value, the less requests will be made during replay. (default 1000)
2021-06-09 09:20:38 +00:00
-replay.ruleRetryAttempts int
2021-08-11 07:29:33 +00:00
Defines how many retries to make before giving up on rule if request for it returns an error. (default 5)
2021-06-09 09:20:38 +00:00
-replay.rulesDelay duration
2021-08-11 07:29:33 +00:00
Delay between rules evaluation within the group. Could be important if there are chained rules inside of the groupand processing need to wait for previous rule results to be persisted by remote storage before evaluating the next rule.Keep it equal or bigger than -remoteWrite.flushInterval. (default 1s)
2021-06-09 09:20:38 +00:00
-replay.timeFrom string
2021-08-11 07:29:33 +00:00
The time filter in RFC3339 format to select time series with timestamp equal or higher than provided value. E.g. '2020-01-01T20:07:00Z'
2021-06-09 09:20:38 +00:00
-replay.timeTo string
2021-08-11 07:29:33 +00:00
The time filter in RFC3339 format to select timeseries with timestamp equal or lower than provided value. E.g. '2020-01-01T20:07:00Z'
2020-08-14 16:13:24 +00:00
-rule array
2021-08-11 07:29:33 +00:00
Path to the file with alert rules.
Supports patterns. Flag can be specified multiple times.
Examples:
-rule="/path/to/file". Path to a single file with alerting rules
-rule="dir/*.yaml" -rule="/*.yaml". Relative path to all .yaml files in "dir" folder,
absolute path to all .yaml files in root.
Rule files may contain %{ENV_VAR} placeholders, which are substituted by the corresponding env vars.
Supports an array of values separated by comma or specified via multiple flags.
2021-05-25 13:27:22 +00:00
-rule.configCheckInterval duration
2021-08-11 07:29:33 +00:00
Interval for checking for changes in '-rule' files. By default the checking is disabled. Send SIGHUP signal in order to force config check for changes
2020-06-06 20:27:09 +00:00
-rule.validateExpressions
2021-08-11 07:29:33 +00:00
Whether to validate rules expressions via MetricsQL engine (default true)
2020-04-26 11:15:04 +00:00
-rule.validateTemplates
2021-08-11 07:29:33 +00:00
Whether to validate annotation and label templates (default true)
2020-08-14 16:13:24 +00:00
-tls
2021-08-11 07:29:33 +00:00
Whether to enable TLS (aka HTTPS) for incoming requests. -tlsCertFile and -tlsKeyFile must be set if -tls is set
2020-08-14 16:13:24 +00:00
-tlsCertFile string
2021-08-11 07:29:33 +00:00
Path to file with TLS certificate. Used only if -tls is set. Prefer ECDSA certs instead of RSA certs as RSA certs are slower
2020-08-14 16:13:24 +00:00
-tlsKeyFile string
2021-08-11 07:29:33 +00:00
Path to file with TLS key. Used only if -tls is set
2020-08-14 16:13:24 +00:00
-version
2021-08-11 07:29:33 +00:00
Show VictoriaMetrics version
2020-04-12 11:47:26 +00:00
```
2021-05-25 13:27:22 +00:00
`vmalert` supports "hot" config reload via the following methods:
* send SIGHUP signal to `vmalert` process;
* send GET request to `/-/reload` endpoint;
* configure `-rule.configCheckInterval` flag for periodic reload
on config change.
2020-05-10 16:58:17 +00:00
2021-04-07 10:39:16 +00:00
## Contributing
2020-04-12 11:47:26 +00:00
`vmalert` is mostly designed and built by VictoriaMetrics community.
2021-03-09 20:49:50 +00:00
Feel free to share your experience and ideas for improving this
2020-04-29 09:39:15 +00:00
software. Please keep simplicity as the main priority.
2020-05-14 20:32:58 +00:00
2021-04-07 10:39:16 +00:00
## How to build from sources
2020-05-14 20:32:58 +00:00
2021-03-09 20:49:50 +00:00
It is recommended using
[binary releases ](https://github.com/VictoriaMetrics/VictoriaMetrics/releases )
2020-05-14 20:32:58 +00:00
- `vmalert` is located in `vmutils-*` archives there.
2021-04-07 10:39:16 +00:00
### Development build
2020-05-14 20:32:58 +00:00
2021-07-07 14:28:06 +00:00
1. [Install Go ](https://golang.org/doc/install ). The minimum supported version is Go 1.16.
2021-03-25 15:14:38 +00:00
2. Run `make vmalert` from the root folder of [the repository ](https://github.com/VictoriaMetrics/VictoriaMetrics ).
2020-05-14 20:32:58 +00:00
It builds `vmalert` binary and puts it into the `bin` folder.
2021-04-07 10:39:16 +00:00
### Production build
2020-05-14 20:32:58 +00:00
1. [Install docker ](https://docs.docker.com/install/ ).
2021-03-25 15:14:38 +00:00
2. Run `make vmalert-prod` from the root folder of [the repository ](https://github.com/VictoriaMetrics/VictoriaMetrics ).
2020-05-14 20:32:58 +00:00
It builds `vmalert-prod` binary and puts it into the `bin` folder.
2020-07-31 06:25:15 +00:00
2021-04-07 10:39:16 +00:00
### ARM build
2020-07-31 06:25:15 +00:00
ARM build may run on Raspberry Pi or on [energy-efficient ARM servers ](https://blog.cloudflare.com/arm-takes-wing/ ).
2021-04-07 10:39:16 +00:00
### Development ARM build
2020-07-31 06:25:15 +00:00
2021-07-07 14:28:06 +00:00
1. [Install Go ](https://golang.org/doc/install ). The minimum supported version is Go 1.16.
2021-03-25 15:14:38 +00:00
2. Run `make vmalert-arm` or `make vmalert-arm64` from the root folder of [the repository ](https://github.com/VictoriaMetrics/VictoriaMetrics ).
2020-07-31 06:25:15 +00:00
It builds `vmalert-arm` or `vmalert-arm64` binary respectively and puts it into the `bin` folder.
2021-04-07 10:39:16 +00:00
### Production ARM build
2020-07-31 06:25:15 +00:00
1. [Install docker ](https://docs.docker.com/install/ ).
2021-03-25 15:14:38 +00:00
2. Run `make vmalert-arm-prod` or `make vmalert-arm64-prod` from the root folder of [the repository ](https://github.com/VictoriaMetrics/VictoriaMetrics ).
2020-07-31 06:25:15 +00:00
It builds `vmalert-arm-prod` or `vmalert-arm64-prod` binary respectively and puts it into the `bin` folder.