at 24.11-pre 2.7 kB view raw
1{ config, pkgs, lib, ... }: 2let cfg = config.services.victoriametrics; in 3{ 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 { 8 default = ":8428"; 9 type = types.str; 10 description = '' 11 The listen address for the http interface. 12 ''; 13 }; 14 retentionPeriod = mkOption { 15 type = types.int; 16 default = 1; 17 description = '' 18 Retention period in months. 19 ''; 20 }; 21 extraOptions = mkOption { 22 type = types.listOf types.str; 23 default = []; 24 description = '' 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 28 information. 29 ''; 30 }; 31 }; 32 config = lib.mkIf cfg.enable { 33 systemd.services.victoriametrics = { 34 description = "VictoriaMetrics time series database"; 35 after = [ "network.target" ]; 36 startLimitBurst = 5; 37 serviceConfig = { 38 Restart = "on-failure"; 39 RestartSec = 1; 40 StateDirectory = "victoriametrics"; 41 DynamicUser = true; 42 ExecStart = '' 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} 48 ''; 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. 51 # 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; 57 }; 58 wantedBy = [ "multi-user.target" ]; 59 60 postStart = 61 let 62 bindAddr = (lib.optionalString (lib.hasPrefix ":" cfg.listenAddress) "127.0.0.1") + cfg.listenAddress; 63 in 64 lib.mkBefore '' 65 until ${lib.getBin pkgs.curl}/bin/curl -s -o /dev/null http://${bindAddr}/ping; do 66 sleep 1; 67 done 68 ''; 69 }; 70 }; 71}