2022-10-09 09:19:24 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.vmagent;
|
|
|
|
settingsFormat = pkgs.formats.json { };
|
|
|
|
in {
|
|
|
|
options.services.vmagent = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "vmagent";
|
2022-10-09 09:19:24 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "vmagent";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
User account under which vmagent runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "vmagent";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
Group under which vmagent runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "vmagent" { };
|
2022-10-09 09:19:24 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/vmagent";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
The directory where vmagent stores its data files.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
remoteWriteUrl = mkOption {
|
|
|
|
default = "http://localhost:8428/api/v1/write";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
The storage endpoint such as VictoriaMetrics
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
prometheusConfig = mkOption {
|
|
|
|
type = lib.types.submodule { freeformType = settingsFormat.type; };
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
Config for prometheus style metrics
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-09 09:19:24 +00:00
|
|
|
Whether to open the firewall for the default ports.
|
|
|
|
'';
|
|
|
|
};
|
2023-08-24 12:18:09 +00:00
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-08-24 12:18:09 +00:00
|
|
|
Extra args to pass to `vmagent`. See the docs:
|
|
|
|
<https://docs.victoriametrics.com/vmagent.html#advanced-usage>
|
|
|
|
or {command}`vmagent -help` for more information.
|
|
|
|
'';
|
|
|
|
};
|
2022-10-09 09:19:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "vmagent") {
|
|
|
|
vmagent = {
|
|
|
|
group = cfg.group;
|
|
|
|
description = "vmagent daemon user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
|
|
|
|
|
|
|
|
systemd.services.vmagent = let
|
|
|
|
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
|
|
|
|
in {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
description = "vmagent system service";
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
2023-08-24 12:18:09 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${escapeShellArgs cfg.extraArgs}";
|
2022-10-09 09:19:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules =
|
|
|
|
[ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
|
|
|
|
};
|
|
|
|
}
|