diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 6e677fe04b7d..5fda9284d6f6 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -6462,6 +6462,12 @@ githubId = 752510; name = "Martin Potier"; }; + jqqqqqqqqqq = { + email = "jqqqqqqqqqq@gmail.com"; + github = "jqqqqqqqqqq"; + githubId = 12872927; + name = "Curtis Jiang"; + }; jqueiroz = { email = "nixos@johnjq.com"; github = "jqueiroz"; diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 47c30a0f24bb..68c766be63ec 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -72,6 +72,7 @@ let "unbound" "unifi" "unifi-poller" + "v2ray" "varnish" "wireguard" "flow" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/v2ray.nix b/nixos/modules/services/monitoring/prometheus/exporters/v2ray.nix new file mode 100644 index 000000000000..185506cfc2b7 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/v2ray.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.v2ray; +in +{ + port = 9299; + extraOpts = { + v2rayEndpoint = mkOption { + type = types.str; + default = "127.0.0.1:54321"; + description = '' + v2ray grpc api endpoint + ''; + }; + }; + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.prometheus-v2ray-exporter}/bin/v2ray-exporter \ + --v2ray-endpoint ${cfg.v2rayEndpoint} \ + --listen ${cfg.listenAddress}:${toString cfg.port} \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 4fdff7dbdab8..3b9ca4f0aa6a 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1256,6 +1256,67 @@ let ''; }; + v2ray = { + exporterConfig = { + enable = true; + }; + + metricProvider = { + systemd.services.prometheus-nginx-exporter.after = [ "v2ray.service" ]; + services.v2ray = { + enable = true; + config = { + stats = {}; + api = { + tag = "api"; + services = [ "StatsService" ]; + }; + inbounds = [ + { + port = 1080; + listen = "127.0.0.1"; + protocol = "http"; + } + { + listen = "127.0.0.1"; + port = 54321; + protocol = "dokodemo-door"; + settings = { address = "127.0.0.1"; }; + tag = "api"; + } + ]; + outbounds = [ + { + protocol = "freedom"; + } + { + protocol = "freedom"; + settings = {}; + tag = "api"; + } + ]; + routing = { + strategy = "rules"; + settings = { + rules = [ + { + inboundTag = [ "api" ]; + outboundTag = "api"; + type = "field"; + } + ]; + }; + }; + }; + }; + }; + exporterTest = '' + wait_for_unit("prometheus-v2ray-exporter.service") + wait_for_open_port(9299) + succeed("curl -sSf localhost:9299/scrape | grep 'v2ray_up 1'") + ''; + }; + varnish = { exporterConfig = { enable = true; diff --git a/pkgs/servers/monitoring/prometheus/v2ray-exporter.nix b/pkgs/servers/monitoring/prometheus/v2ray-exporter.nix new file mode 100644 index 000000000000..c8732e85315f --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/v2ray-exporter.nix @@ -0,0 +1,22 @@ +{ lib, buildGoModule, fetchFromGitHub }: + +buildGoModule rec { + pname = "v2ray-exporter"; + version = "0.6.0"; + + src = fetchFromGitHub { + owner = "wi1dcard"; + repo = "v2ray-exporter"; + rev = "v${version}"; + sha256 = "12mzng3cw24fyyh8zjfi26gh853k5blzg3zbxcccnv5lryh2r0yi"; + }; + + vendorSha256 = "sha256-+jrD+QatTrMaAdbxy5mpCm8lF37XDIy1GFyEiUibA2k="; + + meta = with lib; { + description = "Prometheus exporter for V2Ray daemon"; + homepage = "https://github.com/wi1dcard/v2ray-exporter"; + license = licenses.mit; + maintainers = with maintainers; [ jqqqqqqqqqq ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b7a26c02ae4d..ef757f00b331 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23319,6 +23319,7 @@ with pkgs; prometheus-unbound-exporter = callPackage ../servers/monitoring/prometheus/unbound-exporter.nix { inherit (darwin.apple_sdk.frameworks) Security; }; + prometheus-v2ray-exporter = callPackage ../servers/monitoring/prometheus/v2ray-exporter.nix { }; prometheus-varnish-exporter = callPackage ../servers/monitoring/prometheus/varnish-exporter.nix { }; prometheus-wireguard-exporter = callPackage ../servers/monitoring/prometheus/wireguard-exporter.nix { inherit (darwin.apple_sdk.frameworks) Security;