2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let cfg = config.services.victoriametrics; in
|
|
|
|
{
|
|
|
|
options.services.victoriametrics = with lib; {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "victoriametrics");
|
2020-04-24 23:36:52 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.victoriametrics;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.victoriametrics";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The VictoriaMetrics distribution to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
listenAddress = mkOption {
|
|
|
|
default = ":8428";
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The listen address for the http interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
retentionPeriod = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Retention period in months.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Extra options to pass to VictoriaMetrics. See the README:
|
|
|
|
<https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/README.md>
|
|
|
|
or {command}`victoriametrics -help` for more
|
2020-04-24 23:36:52 +00:00
|
|
|
information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.victoriametrics = {
|
|
|
|
description = "VictoriaMetrics time series database";
|
|
|
|
after = [ "network.target" ];
|
2020-11-03 02:18:15 +00:00
|
|
|
startLimitBurst = 5;
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 1;
|
|
|
|
StateDirectory = "victoriametrics";
|
|
|
|
DynamicUser = true;
|
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/victoria-metrics \
|
|
|
|
-storageDataPath=/var/lib/victoriametrics \
|
2020-09-25 04:45:31 +00:00
|
|
|
-httpListenAddr ${cfg.listenAddress} \
|
|
|
|
-retentionPeriod ${toString cfg.retentionPeriod} \
|
2020-04-24 23:36:52 +00:00
|
|
|
${lib.escapeShellArgs cfg.extraOptions}
|
|
|
|
'';
|
2021-08-08 23:34:03 +00:00
|
|
|
# victoriametrics 1.59 with ~7GB of data seems to eventually panic when merging files and then
|
|
|
|
# begins restart-looping forever. Set LimitNOFILE= to a large number to work around this issue.
|
|
|
|
#
|
|
|
|
# panic: FATAL: unrecoverable error when merging small parts in the partition "/var/lib/victoriametrics/data/small/2021_08":
|
|
|
|
# cannot open source part for merging: cannot open values file in stream mode:
|
|
|
|
# cannot open file "/var/lib/victoriametrics/data/small/2021_08/[...]/values.bin":
|
|
|
|
# open /var/lib/victoriametrics/data/small/2021_08/[...]/values.bin: too many open files
|
|
|
|
LimitNOFILE = 1048576;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
postStart =
|
|
|
|
let
|
|
|
|
bindAddr = (lib.optionalString (lib.hasPrefix ":" cfg.listenAddress) "127.0.0.1") + cfg.listenAddress;
|
|
|
|
in
|
|
|
|
lib.mkBefore ''
|
|
|
|
until ${lib.getBin pkgs.curl}/bin/curl -s -o /dev/null http://${bindAddr}/ping; do
|
|
|
|
sleep 1;
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|