1 { config, pkgs, lib, ... }:
2 let cfg = config.services.victoriametrics; in
4 options.services.victoriametrics = with lib; {
5 enable = mkEnableOption "VictoriaMetrics, a time series database, long-term remote storage for Prometheus";
6 package = mkPackageOption pkgs "victoriametrics" { };
7 listenAddress = mkOption {
11 The listen address for the http interface.
14 retentionPeriod = mkOption {
18 Retention period in months.
21 extraOptions = mkOption {
22 type = types.listOf types.str;
25 Extra options to pass to VictoriaMetrics. See the README:
26 <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/README.md>
27 or {command}`victoriametrics -help` for more
32 config = lib.mkIf cfg.enable {
33 systemd.services.victoriametrics = {
34 description = "VictoriaMetrics time series database";
35 after = [ "network.target" ];
38 Restart = "on-failure";
40 StateDirectory = "victoriametrics";
43 ${cfg.package}/bin/victoria-metrics \
44 -storageDataPath=/var/lib/victoriametrics \
45 -httpListenAddr ${cfg.listenAddress} \
46 -retentionPeriod ${toString cfg.retentionPeriod} \
47 ${lib.escapeShellArgs cfg.extraOptions}
49 # victoriametrics 1.59 with ~7GB of data seems to eventually panic when merging files and then
50 # begins restart-looping forever. Set LimitNOFILE= to a large number to work around this issue.
52 # panic: FATAL: unrecoverable error when merging small parts in the partition "/var/lib/victoriametrics/data/small/2021_08":
53 # cannot open source part for merging: cannot open values file in stream mode:
54 # cannot open file "/var/lib/victoriametrics/data/small/2021_08/[...]/values.bin":
55 # open /var/lib/victoriametrics/data/small/2021_08/[...]/values.bin: too many open files
56 LimitNOFILE = 1048576;
58 wantedBy = [ "multi-user.target" ];
62 bindAddr = (lib.optionalString (lib.hasPrefix ":" cfg.listenAddress) "127.0.0.1") + cfg.listenAddress;
65 until ${lib.getBin pkgs.curl}/bin/curl -s -o /dev/null http://${bindAddr}/ping; do