xray-health-exporter

by batonogov

Helm chartv0.4.12App 1.8.3Verified publisher

Prometheus exporter for Xray-core tunnel health

About this chart

xray-health-exporter

Prometheus exporter for Xray-core tunnel health

Homepage: https://github.com/batonogov/xray-health-exporter

TL;DR

Create a values file with at least one tunnel or subscription:

# values.yaml
config:
  tunnels:
    - name: edge-1
      url: "vless://uuid@host1:443?type=tcp&security=reality&pbk=...&sni=google.com"

The example is a placeholder: real VLESS URLs and their UUIDs are credentials. Like subscription URLs with tokens, they are stored in a plain ConfigMap when set through .Values.config. For real credentials, provide the complete config.yaml through existingConfigSecret instead.

Then install the chart:

helm repo add batonogov https://batonogov.github.io/helm-charts
helm install xray batonogov/xray-health-exporter -n monitoring --create-namespace \
  -f values.yaml

Prerequisites

  • Kubernetes 1.32+
  • Helm 3.14+
  • For ServiceMonitor/PrometheusRule: the Prometheus Operator CRDs installed in the cluster
  • For replicaCount > 1: leader election (default) requires a Role granting access to coordination.k8s.io/leases — created automatically by the chart

High availability

The chart force-enables Kubernetes leader election whenever replicaCount > 1, regardless of leaderElection.enabled. Only the leader publishes xray_tunnel_* series; followers continue to serve /health and a single xray_exporter_leader=0 metric so a Service can still load-balance and the Prometheus Operator can keep scraping every pod without duplicated tunnel metrics.

Failover timing matches the upstream defaults: ~5s on graceful leader exit, ~30s on hard pod loss.

Configuration

The exporter is driven by a YAML file. Set .Values.config to render a ConfigMap, or point existingConfigSecret at a Secret you manage out of band. Use a Secret for subscription tokens, authentication headers, and static share links containing credentials.

When using existingConfigSecret, restart the exporter Deployment after changing the Secret. The chart mounts config.yaml through subPath, so the mounted file is not updated in running pods; they keep using the old configuration until the pods are recreated.

config:
  defaults:
    check_url: https://www.google.com
    check_interval: 30s
    check_timeout: 30s
    max_backoff: 5m
    backoff_multiplier: 2.0
  subscriptions:
    - url: https://provider.example.com/subscribe?token=xxx
      update_interval: 1h
  tunnels:
    - name: edge-1
      url: "vless://uuid@host1:443?type=xhttp&security=reality&pbk=...&sni=example.com&fp=chrome&path=%2Fapi&mode=stream-up"

Static share links support VLESS, VMess, Trojan, and Shadowsocks. Subscriptions accept text/Base64 links, native Xray JSON, and a supported subset of Clash proxy lists. See the upstream configuration reference for supported formats, transports, subscription fields, and validation rules.

Upgrading to v1.8.0

Check existing subscription contents: unsupported entries now reject the entire response instead of being skipped. An initial fetch failure prevents startup; failed refreshes retain the last accepted list in memory until restart. Check intervals, request timeouts, and max_backoff must be strictly positive; invalid values reject startup or configuration reload.

Native Xray JSON configurations

An entry using xray_config_file must reference a file mounted into the exporter container. Store the native JSON in a Secret in the Helm release namespace, then mount that Secret with extraVolumes and extraVolumeMounts:

kubectl create secret generic xray-native-config \
  --namespace monitoring \
  --from-file=outbound.json
config:
  tunnels:
    - name: native-outbound
      xray_config_file: /etc/xray/outbound.json

extraVolumes:
  - name: native-config
    secret:
      secretName: xray-native-config

extraVolumeMounts:
  - name: native-config
    mountPath: /etc/xray
    readOnly: true

Avoid the reserved volume names config and tmp, which the chart uses for the exporter configuration and writable temporary directory. Restart the exporter pods after updating a referenced native JSON Secret: upstream watches the main exporter YAML file, not the referenced Xray JSON files.

Prometheus integration

Set metrics.serviceMonitor.enabled=true to register the exporter with the Prometheus Operator. Set metrics.prometheusRule.enabled=true to ship the default tunnel alerts (XrayTunnelDown, XrayHighLatency, XrayNoRecentCheck); override metrics.prometheusRule.rules to provide your own list.

For a cross-namespace ServiceMonitor, the chart selects Services in the release namespace. The default NetworkPolicy then allows Prometheus-labelled pods from the ServiceMonitor namespace; explicit networkPolicy.ingress rules replace this default.

Health-check methods (v1.6.0+)

The exporter supports three check methods, configurable globally via env.CHECK_METHOD or per tunnel via config.defaults.check_method / tunnel-level check_method:

  • http (default) — HTTP GET against check_url; status 200, 301, 302, or 307 succeeds
  • ip — require status 200 from IP_CHECK_URL and verify that the tunnel's exit IP differs from the host's public IP
  • download — require status 200 from DOWNLOAD_URL and receive at least download_min_size bytes within download_timeout

All three measure latency as TTFB (time to first byte).

Securing the metrics endpoint (v1.6.0+)

Set metricsBasicAuth.enabled=true to protect /metrics with HTTP Basic Auth. The chart provisions a stable Secret holding both the username and password (reused on upgrade so they do not rotate) unless you point metricsBasicAuth.existingSecret at your own Secret. The Secret must contain the configured username and password keys in the release namespace.

When metrics.serviceMonitor.enabled=true is also set, the chart injects matching basicAuth credentials into the ServiceMonitor automatically, so Prometheus scrapes succeed without extra configuration. The username and password keys are configurable via metricsBasicAuth.usernameKey / metricsBasicAuth.passwordKey.

Note: The exporter reads its Secret in the release namespace, while Prometheus Operator reads the referenced Secret in the ServiceMonitor's namespace. For a cross-namespace ServiceMonitor, set metricsBasicAuth.existingSecret and provision Secrets with that same name and the same configured keys in both namespaces.

After rotating an external Basic Auth Secret, restart the exporter pods so they read the new credentials.

Pushing to Pushgateway (v1.6.0+)

Set metricsPush.url to additionally push metrics to a Pushgateway. Push is complementary to the /metrics pull endpoint and only the leader pushes.

To avoid leaking Pushgateway credentials in the rendered Deployment (and in etcd), point metricsPush.urlSecret.name at an existing Secret holding the full URL (key url by default) when the URL embeds user:pass@ — it takes precedence over metricsPush.url. After rotating that Secret, restart the exporter pods so they read the new URL.

Requirements

Kubernetes: >=1.32.0-0

Values

KeyTypeDefaultDescription
affinityobject{}Affinity rules for the pod.
config.defaultsobject{"backoff_multiplier":2,"check_interval":"30s","check_timeout":"30s","check_url":"https://www.google.com","max_backoff":"5m"}Global tunnel-check defaults applied when an entry omits the field.
config.defaults.backoff_multiplierfloat2Exponential backoff growth factor after failures (must be at least 1.0).
config.defaults.max_backoffstring"5m"Maximum interval between checks after repeated failures (Go duration).
config.subscriptionslist[]Subscription URLs that auto-discover tunnels. See upstream README for schema. WARNING: subscription URLs typically embed access tokens — they are rendered into a plain ConfigMap. Use existingConfigSecret to source config.yaml from a Secret instead.
config.tunnelslist[]Static tunnels. Each entry needs either url (a VLESS, VMess, Trojan, or Shadowsocks share link) or xray_config_file. Share URLs contain credentials and are rendered into a plain ConfigMap; use existingConfigSecret for real credentials. At least one tunnel or one subscription is required (or set existingConfigSecret); otherwise the exporter refuses to start.
env.CHECK_METHODstring"http"Default health-check method used when a tunnel omits check_method. http (HTTP GET), ip (IP echo via IP_CHECK_URL), or download (file download via DOWNLOAD_URL).
env.DOWNLOAD_MIN_SIZEstring"51200"Minimum downloaded bytes for the download method to be considered successful.
env.DOWNLOAD_TIMEOUTstring"60s"Timeout for the download check method (Go duration, e.g. 60s, 2m).
env.DOWNLOAD_URLstring"https://proof.ovh.net/files/1Mb.dat"File URL for the download check method.
env.IP_CHECK_URLstring"https://api.ipify.org?format=text"IP-echo URL for the ip check method.
env.LOG_FORMATstring"text"Exporter log format (text or json).
env.LOG_LEVELstring"info"Exporter log level (debug/info/warn/warning/error). Replaces the deprecated DEBUG=true flag.
env.RUN_ONCEstring"false"One-shot mode. If true, run a single check cycle, print metrics to stdout, and exit. Disable for long-running Deployments (useful only for CronJob-style usage).
env.XRAY_LOG_LEVELstring"warning"Xray-core log level (debug/info/warning/error).
existingConfigSecretstring""Mount an existing Secret containing config.yaml instead of rendering one from .Values.config.
extraEnvlist[]Extra environment variables (list of {name, value} or {name, valueFrom}).
extraVolumeMountslist[]Additional volume mounts for the exporter container. Use with extraVolumes, for example to mount native Xray JSON files referenced by config.tunnels[].xray_config_file.
extraVolumeslist[]Additional pod volumes. Avoid the reserved names config and tmp.
fullnameOverridestring""Fully override the generated release name.
image.pullPolicystring"IfNotPresent"Image pull policy.
image.pullSecretslist[]Image pull secrets (list of {name: <secret>}).
image.repositorystring"ghcr.io/batonogov/xray-health-exporter"Image repository.
image.tagstring""Image tag. Defaults to v<chart appVersion> when empty (upstream publishes v-prefixed tags to ghcr.io).
leaderElection.enabledbooltrueEnable Kubernetes leader election so only one replica publishes xray_tunnel_*. Forced on whenever replicaCount > 1, regardless of this flag.
leaderElection.leaseNamestring""Lease object name. Defaults to the release fullname.
leaderElection.rbac.createbooltrueCreate the Role + RoleBinding granting access to coordination.k8s.io/leases.
metrics.prometheusRule.annotationsobject{}Extra annotations.
metrics.prometheusRule.enabledboolfalseCreate a Prometheus Operator PrometheusRule with default tunnel alerts.
metrics.prometheusRule.labelsobject{}Extra labels on the PrometheusRule (e.g. release: kube-prometheus-stack).
metrics.prometheusRule.ruleslist[]Override the default rule list. When empty the chart ships sensible defaults (XrayTunnelDown, XrayHighLatency, XrayNoRecentCheck).
metrics.serviceMonitor.annotationsobject{}Extra annotations on the ServiceMonitor.
metrics.serviceMonitor.enabledboolfalseCreate a Prometheus Operator ServiceMonitor for the exporter.
metrics.serviceMonitor.intervalstring"30s"Scrape interval.
metrics.serviceMonitor.labelsobject{}Extra labels (e.g. release: kube-prometheus-stack).
metrics.serviceMonitor.metricRelabelingslist[]Optional metric relabelings.
metrics.serviceMonitor.namespacestring""Namespace for the ServiceMonitor. Defaults to the release namespace.
metrics.serviceMonitor.relabelingslist[]Optional relabelings.
metrics.serviceMonitor.scrapeTimeoutstring"10s"Scrape timeout.
metricsBasicAuth.enabledboolfalseProtect /metrics with HTTP Basic Auth. When true, the METRICS_PROTECTED/METRICS_USERNAME/METRICS_PASSWORD envs are rendered.
metricsBasicAuth.existingSecretstring""Use an existing Secret instead of a chart-generated one. Takes precedence over the generated Secret and secretName. The Secret must contain the configured username and password keys in the release namespace. For a cross-namespace ServiceMonitor, provision a Secret with the same name and keys in both the release and ServiceMonitor namespaces.
metricsBasicAuth.passwordKeystring""Key inside the Secret holding the password (default password).
metricsBasicAuth.secretNamestring""Name override for the chart-generated Secret holding the Basic Auth credentials. Defaults to <release>-basicauth. Ignored when existingSecret is set.
metricsBasicAuth.usernamestring""Username. Defaults to upstream's metricsUser when empty.
metricsBasicAuth.usernameKeystring""Key

Deploy xray-health-exporter with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has xray-health-exporter on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartxray-health-exporter is pinned at v0.4.12 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply