From 28d2fcc400c26a5c48e6affcdc82892283595423 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 9 Oct 2022 11:19:24 +0200 Subject: [PATCH] vmagent: init at 1.82.0 --- nixos/modules/module-list.nix | 1 + nixos/modules/services/monitoring/vmagent.nix | 100 ++++++++++++++++++ pkgs/servers/monitoring/vmagent/default.nix | 26 +++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 129 insertions(+) create mode 100644 nixos/modules/services/monitoring/vmagent.nix create mode 100644 pkgs/servers/monitoring/vmagent/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index db07d6312c42..e45f80957ffe 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -713,6 +713,7 @@ ./services/monitoring/unifi-poller.nix ./services/monitoring/ups.nix ./services/monitoring/uptime.nix + ./services/monitoring/vmagent.nix ./services/monitoring/vnstat.nix ./services/monitoring/zabbix-agent.nix ./services/monitoring/zabbix-proxy.nix diff --git a/nixos/modules/services/monitoring/vmagent.nix b/nixos/modules/services/monitoring/vmagent.nix new file mode 100644 index 000000000000..c793bb073199 --- /dev/null +++ b/nixos/modules/services/monitoring/vmagent.nix @@ -0,0 +1,100 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.services.vmagent; + settingsFormat = pkgs.formats.json { }; +in { + options.services.vmagent = { + enable = mkEnableOption (lib.mdDoc "vmagent"); + + user = mkOption { + default = "vmagent"; + type = types.str; + description = lib.mdDoc '' + User account under which vmagent runs. + ''; + }; + + group = mkOption { + type = types.str; + default = "vmagent"; + description = lib.mdDoc '' + Group under which vmagent runs. + ''; + }; + + package = mkOption { + default = pkgs.vmagent; + defaultText = lib.literalMD "pkgs.vmagent"; + type = types.package; + description = lib.mdDoc '' + vmagent package to use. + ''; + }; + + dataDir = mkOption { + type = types.str; + default = "/var/lib/vmagent"; + description = lib.mdDoc '' + The directory where vmagent stores its data files. + ''; + }; + + remoteWriteUrl = mkOption { + default = "http://localhost:8428/api/v1/write"; + type = types.str; + description = lib.mdDoc '' + The storage endpoint such as VictoriaMetrics + ''; + }; + + prometheusConfig = mkOption { + type = lib.types.submodule { freeformType = settingsFormat.type; }; + description = lib.mdDoc '' + Config for prometheus style metrics + ''; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Whether to open the firewall for the default ports. + ''; + }; + }; + + 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; + ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}"; + }; + }; + + systemd.tmpfiles.rules = + [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ]; + }; +} diff --git a/pkgs/servers/monitoring/vmagent/default.nix b/pkgs/servers/monitoring/vmagent/default.nix new file mode 100644 index 000000000000..df7a5ee987bf --- /dev/null +++ b/pkgs/servers/monitoring/vmagent/default.nix @@ -0,0 +1,26 @@ +{ lib, fetchFromGitHub, buildGoModule }: +buildGoModule rec { + pname = "vmagent"; + version = "1.82.0"; + + src = fetchFromGitHub { + owner = "VictoriaMetrics"; + repo = "VictoriaMetrics"; + rev = "v${version}"; + sha256 = "JIl2WeveDoAHzqJ2cqMxpWeNf4yQC9fIdfECOJywJ2A="; + }; + + ldflags = [ "-s" "-w" "-X github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo.Version=${version}" ]; + + vendorSha256 = null; + + subPackages = [ "app/vmagent" ]; + + meta = with lib; { + homepage = "https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/app/vmagent"; + description = "VictoriaMetrics metrics scraper"; + license = licenses.asl20; + platforms = platforms.linux; + maintainers = with maintainers; [ nullx76 ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b51c0bbbe3d0..07ad765c2f82 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24174,6 +24174,8 @@ with pkgs; virtualenv-clone = with python3Packages; toPythonApplication virtualenv-clone; + vmagent = callPackage ../servers/monitoring/vmagent { }; + vsftpd = callPackage ../servers/ftp/vsftpd { }; wallabag = callPackage ../servers/web-apps/wallabag { };