prometheus-xray-exporter: init at 0.2.0

This commit is contained in:
xiaodong.jia
2026-06-11 19:03:55 +08:00
parent 6109c8b602
commit f07ac86aa7
3 changed files with 106 additions and 0 deletions
@@ -133,6 +133,7 @@ let
"v2ray"
"varnish"
"wireguard"
"xray"
"zfs-siebenmann"
"zfs"
]
@@ -0,0 +1,77 @@
{
config,
lib,
pkgs,
options,
...
}:
let
cfg = config.services.prometheus.exporters.xray;
inherit (lib)
mkOption
types
concatStringsSep
optionalString
;
in
{
port = 9550;
extraOpts = {
xrayEndpoint = mkOption {
type = types.str;
default = "127.0.0.1:8080";
description = ''
Xray gRPC API endpoint.
'';
};
metricsPath = mkOption {
type = types.str;
default = "/scrape";
description = ''
Path under which to expose metrics.
'';
};
scrapeTimeout = mkOption {
type = types.int;
default = 5;
description = ''
Timeout in seconds for every individual scrape.
'';
};
logPath = mkOption {
type = types.str;
default = "/var/log/xray/access.log";
description = ''
Path to Xray access log file. Set to empty string to disable user metrics.
'';
};
logTimeWindow = mkOption {
type = types.int;
default = 5;
description = ''
Time window in minutes for user metrics.
'';
};
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-xray-exporter}/bin/xray-exporter \
--listen ${cfg.listenAddress}:${toString cfg.port} \
--metrics-path ${cfg.metricsPath} \
--xray-endpoint ${cfg.xrayEndpoint} \
--scrape-timeout ${toString cfg.scrapeTimeout} \
${optionalString (cfg.logPath != "") "--log-path ${cfg.logPath}"} \
--log-time-window ${toString cfg.logTimeWindow} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}
@@ -0,0 +1,28 @@
{
buildGoModule,
lib,
fetchFromGitHub,
}:
buildGoModule (finalAttrs: {
__structuredAttrs = true;
pname = "prometheus-xray-exporter";
version = "0.2.0";
src = fetchFromGitHub {
owner = "compassvpn";
repo = "xray-exporter";
tag = "v${finalAttrs.version}";
hash = "sha256-GP0CFphMgSS8ezSuRoHQJMuehCND4glrXE9fye0PhTE=";
};
vendorHash = "sha256-yRxy44SnEFa7yOJyiOgFTk+Z4s5HOJ4cMjcf8VTTfQk=";
meta = {
description = "Prometheus exporter for Xray-core metrics";
mainProgram = "xray-exporter";
homepage = "https://github.com/compassvpn/xray-exporter";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ podocarp ];
};
})