Merge pull request #195205 from NULLx76/vmagent

authored by Sandro and committed by GitHub 2917c9a6 27abdcbc

+129
+1
nixos/modules/module-list.nix
··· 715 715 ./services/monitoring/unifi-poller.nix 716 716 ./services/monitoring/ups.nix 717 717 ./services/monitoring/uptime.nix 718 + ./services/monitoring/vmagent.nix 718 719 ./services/monitoring/vnstat.nix 719 720 ./services/monitoring/zabbix-agent.nix 720 721 ./services/monitoring/zabbix-proxy.nix
+100
nixos/modules/services/monitoring/vmagent.nix
··· 1 + { config, pkgs, lib, ... }: 2 + with lib; 3 + let 4 + cfg = config.services.vmagent; 5 + settingsFormat = pkgs.formats.json { }; 6 + in { 7 + options.services.vmagent = { 8 + enable = mkEnableOption (lib.mdDoc "vmagent"); 9 + 10 + user = mkOption { 11 + default = "vmagent"; 12 + type = types.str; 13 + description = lib.mdDoc '' 14 + User account under which vmagent runs. 15 + ''; 16 + }; 17 + 18 + group = mkOption { 19 + type = types.str; 20 + default = "vmagent"; 21 + description = lib.mdDoc '' 22 + Group under which vmagent runs. 23 + ''; 24 + }; 25 + 26 + package = mkOption { 27 + default = pkgs.vmagent; 28 + defaultText = lib.literalMD "pkgs.vmagent"; 29 + type = types.package; 30 + description = lib.mdDoc '' 31 + vmagent package to use. 32 + ''; 33 + }; 34 + 35 + dataDir = mkOption { 36 + type = types.str; 37 + default = "/var/lib/vmagent"; 38 + description = lib.mdDoc '' 39 + The directory where vmagent stores its data files. 40 + ''; 41 + }; 42 + 43 + remoteWriteUrl = mkOption { 44 + default = "http://localhost:8428/api/v1/write"; 45 + type = types.str; 46 + description = lib.mdDoc '' 47 + The storage endpoint such as VictoriaMetrics 48 + ''; 49 + }; 50 + 51 + prometheusConfig = mkOption { 52 + type = lib.types.submodule { freeformType = settingsFormat.type; }; 53 + description = lib.mdDoc '' 54 + Config for prometheus style metrics 55 + ''; 56 + }; 57 + 58 + openFirewall = mkOption { 59 + type = types.bool; 60 + default = false; 61 + description = lib.mdDoc '' 62 + Whether to open the firewall for the default ports. 63 + ''; 64 + }; 65 + }; 66 + 67 + config = mkIf cfg.enable { 68 + users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; }; 69 + 70 + users.users = mkIf (cfg.user == "vmagent") { 71 + vmagent = { 72 + group = cfg.group; 73 + description = "vmagent daemon user"; 74 + home = cfg.dataDir; 75 + isSystemUser = true; 76 + }; 77 + }; 78 + 79 + networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ]; 80 + 81 + systemd.services.vmagent = let 82 + prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig; 83 + in { 84 + wantedBy = [ "multi-user.target" ]; 85 + after = [ "network.target" ]; 86 + description = "vmagent system service"; 87 + serviceConfig = { 88 + User = cfg.user; 89 + Group = cfg.group; 90 + Type = "simple"; 91 + Restart = "on-failure"; 92 + WorkingDirectory = cfg.dataDir; 93 + ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}"; 94 + }; 95 + }; 96 + 97 + systemd.tmpfiles.rules = 98 + [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ]; 99 + }; 100 + }
+26
pkgs/servers/monitoring/vmagent/default.nix
··· 1 + { lib, fetchFromGitHub, buildGoModule }: 2 + buildGoModule rec { 3 + pname = "vmagent"; 4 + version = "1.82.0"; 5 + 6 + src = fetchFromGitHub { 7 + owner = "VictoriaMetrics"; 8 + repo = "VictoriaMetrics"; 9 + rev = "v${version}"; 10 + sha256 = "JIl2WeveDoAHzqJ2cqMxpWeNf4yQC9fIdfECOJywJ2A="; 11 + }; 12 + 13 + ldflags = [ "-s" "-w" "-X github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo.Version=${version}" ]; 14 + 15 + vendorSha256 = null; 16 + 17 + subPackages = [ "app/vmagent" ]; 18 + 19 + meta = with lib; { 20 + homepage = "https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/app/vmagent"; 21 + description = "VictoriaMetrics metrics scraper"; 22 + license = licenses.asl20; 23 + platforms = platforms.linux; 24 + maintainers = with maintainers; [ nullx76 ]; 25 + }; 26 + }
+2
pkgs/top-level/all-packages.nix
··· 24303 24303 24304 24304 virtualenv-clone = with python3Packages; toPythonApplication virtualenv-clone; 24305 24305 24306 + vmagent = callPackage ../servers/monitoring/vmagent { }; 24307 + 24306 24308 vsftpd = callPackage ../servers/ftp/vsftpd { }; 24307 24309 24308 24310 wallabag = callPackage ../servers/web-apps/wallabag { };