9 cfg = config.services.vmalert;
11 format = pkgs.formats.yaml { };
13 confOpts = concatStringsSep " \\\n" (
14 mapAttrsToList mkLine (filterAttrs (_: v: v != false) cfg.settings)
26 attrsOf (either valueType (listOf valueType));
32 else if isList value then
33 concatMapStringsSep " " (v: "-${key}=${escapeShellArg (toString v)}") value
35 "-${key}=${escapeShellArg (toString value)}";
39 options.services.vmalert = {
40 enable = lib.mkOption {
41 type = lib.types.bool;
44 Wether to enable VictoriaMetrics's `vmalert`.
46 `vmalert` evaluates alerting and recording rules against a data source, sends notifications via Alertmanager.
50 package = mkPackageOption pkgs "victoriametrics" { };
53 type = types.submodule {
54 freeformType = confType;
57 "datasource.url" = mkOption {
58 type = types.nonEmptyStr;
59 example = "http://localhost:8428";
61 Datasource compatible with Prometheus HTTP API.
65 "notifier.url" = mkOption {
66 type = with types; listOf nonEmptyStr;
68 example = [ "http://127.0.0.1:9093" ];
70 Prometheus Alertmanager URL. List all Alertmanager URLs if it runs in the cluster mode to ensure high availability.
75 type = with types; listOf path;
77 Path to the files with alerting and/or recording rules.
80 Consider using the {option}`services.vmalert.rules` option as a convenient alternative for declaring rules
81 directly in the `nix` language.
90 "datasource.url" = "http://localhost:8428";
91 "datasource.disableKeepAlive" = true;
92 "datasource.showURL" = false;
94 "http://<some-server-addr>/path/to/rules"
99 `vmalert` configuration, passed via command line flags. Refer to
100 <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#configuration>
101 for details on supported values.
114 alert = "ExampleAlertAlwaysFiring";
125 A list of the given alerting or recording rules against configured `"datasource.url"` compatible with
126 Prometheus HTTP API for `vmalert` to execute. Refer to
127 <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#rules>
128 for details on supported values.
134 config = mkIf cfg.enable {
136 environment.etc."vmalert/rules.yml".source = format.generate "rules.yml" cfg.rules;
138 services.vmalert.settings.rule = [
139 "/etc/vmalert/rules.yml"
142 systemd.services.vmalert = {
143 description = "vmalert service";
144 wantedBy = [ "multi-user.target" ];
145 after = [ "network.target" ];
146 reloadTriggers = [ config.environment.etc."vmalert/rules.yml".source ];
150 Restart = "on-failure";
151 ExecStart = "${cfg.package}/bin/vmalert ${confOpts}";
152 ExecReload = ''${pkgs.coreutils}/bin/kill -SIGHUP "$MAINPID"'';