[GH-ISSUE #6425] [Feature]: Add a Telegram/email notification event when the outbound changes in the Balancer Observatory #4351

Closed
opened 2026-10-31 20:39:03 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @shlima on GitHub (Sep 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6425

Notification when the outbound changes in the load balancer can help troubleshoot a flaky server without the need to deploy a more complex monitoring infrastructure.

Describe the solution you'd like

Send a notification when the load balancer switches a server in the pool to the fallback server, with debounce/rate limiting to prevent notification spam.

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @shlima on GitHub (Sep 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6425 ### Is your feature request related to a problem? Notification when the outbound changes in the load balancer can help troubleshoot a flaky server without the need to deploy a more complex monitoring infrastructure. ### Describe the solution you'd like Send a notification when the load balancer switches a server in the pool to the fallback server, with debounce/rate limiting to prevent notification spam. ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:39:03 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 5, 2026):

This already exists — the panel has observatory-driven outbound.down / outbound.up events with both a Telegram and an email subscriber, plus the debounce and rate limiting you asked for. It is just off by default.

How to turn it on

  1. Settings → Telegram tab (or the Email tab for SMTP), notification section, "Outbound" group — tick Down and Up. The tab writes tgEnabledEvents / smtpEnabledEvents, whose defaults are login.attempt,cpu.high, i.e. outbound events off (internal/web/service/setting.go:159-160).
  2. Next to the Down checkbox there is a number input for the consecutive-failure threshold (outboundDownThreshold, default 3, accepted range 1–100 — internal/web/entity/entity.go:65, frontend/src/components/ui/notifications/TelegramNotifications.tsx:20-33).
  3. Your Xray template must keep its metrics block — the sampler reads http://<metrics.listen>/debug/vars and gives up with "metrics block not configured in xray template" if it is missing (internal/web/service/xray_metrics.go:147-174). The shipped default already has it:
"metrics": {
  "listen": "127.0.0.1:11111",
  "tag": "metrics_out"
}

Only outbound tags that your balancer's observatory / burstObservatory actually probes appear in that map, so the events follow exactly the same health signal the balancer uses to pick a target.

The debounce/anti-spam you asked for is already there, in two layers:

  • Per-probe failure streak, not per sample. applyObservatory ignores a sample whose lastTry has not advanced — if cur.LastTryTime == 0 || cur.LastTryTime == h.lastTry { continue } (internal/web/service/xray_metrics.go:259-261) — then requires h.failStreak >= threshold && !h.notified before publishing outbound.down (:275), and only sends outbound.up if a down was actually notified (:264). The comment on the outboundHealth type spells out why (:53-58): "Xray flips an outbound's alive flag on a single failed probe, so raw transitions produce a storm of down/up notifications on a flaky link."
  • A 1-minute rate limiter keyed by event type + outbound tag, on both transports: eventbus.NewRateLimiter(1 * time.Minute) at internal/web/service/tgbot/tgbot_event.go:28 (applied at :37) and internal/web/service/email/subscriber.go:28 (applied at :41).

The message bodies are at internal/web/service/tgbot/tgbot_event.go:65-87 (Telegram, includes tag, error and delay) and internal/web/service/email/subscriber.go:92-113 (HTML email). Docs: Telegram bot → events lists outbound.down / outbound.up and tgEnabledEvents.

What genuinely does not exist, and is the only part of your request left open: there is no balancer-level event. The panel notifies per outbound tag, so on a failover you get "Outbound X is DOWN" — nothing names the balancer, and nothing says which fallbackTag took over. fallbackTag is stored and rendered (frontend/src/schemas/xray.ts:137) but never fed to the event bus; the only publishers of outbound events are internal/web/service/xray_metrics.go:265 and :281. For flaky-server troubleshooting the per-tag down/up alert is usually the signal you want, but if a "balancer B switched to fallback F" message is specifically what you need, that part is a real gap and this issue is a reasonable place to track it. I have left it open with the enhancement label for that.

Verdict: Already fixed (shipped for the per-outbound case; the balancer-level event is the remaining gap)

The events landed in eec030f8 feat(notifications): event bus architecture with Telegram and SMTP subscribers (#5326), first released in v3.4.0; the configurable failure threshold in 2b1308ca feat(notifications): add a consecutive-failure threshold for outbound.down alerts (#5968), first released in v3.6.0. Both are in v3.7.0. Related, not duplicates: #6387, #6355, #6305.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5554863729 --> @github-actions[bot] commented on GitHub (Sep 5, 2026): This already exists — the panel has observatory-driven `outbound.down` / `outbound.up` events with both a Telegram and an email subscriber, plus the debounce and rate limiting you asked for. It is just off by default. **How to turn it on** 1. Settings → **Telegram** tab (or the **Email** tab for SMTP), notification section, "Outbound" group — tick **Down** and **Up**. The tab writes `tgEnabledEvents` / `smtpEnabledEvents`, whose defaults are `login.attempt,cpu.high`, i.e. outbound events off (`internal/web/service/setting.go:159-160`). 2. Next to the **Down** checkbox there is a number input for the consecutive-failure threshold (`outboundDownThreshold`, default `3`, accepted range 1–100 — `internal/web/entity/entity.go:65`, `frontend/src/components/ui/notifications/TelegramNotifications.tsx:20-33`). 3. Your Xray template must keep its `metrics` block — the sampler reads `http://<metrics.listen>/debug/vars` and gives up with `"metrics block not configured in xray template"` if it is missing (`internal/web/service/xray_metrics.go:147-174`). The shipped default already has it: ```json "metrics": { "listen": "127.0.0.1:11111", "tag": "metrics_out" } ``` Only outbound tags that your balancer's `observatory` / `burstObservatory` actually probes appear in that map, so the events follow exactly the same health signal the balancer uses to pick a target. **The debounce/anti-spam you asked for is already there**, in two layers: - Per-probe failure streak, not per sample. `applyObservatory` ignores a sample whose `lastTry` has not advanced — `if cur.LastTryTime == 0 || cur.LastTryTime == h.lastTry { continue }` (`internal/web/service/xray_metrics.go:259-261`) — then requires `h.failStreak >= threshold && !h.notified` before publishing `outbound.down` (`:275`), and only sends `outbound.up` if a down was actually notified (`:264`). The comment on the `outboundHealth` type spells out why (`:53-58`): "Xray flips an outbound's alive flag on a single failed probe, so raw transitions produce a storm of down/up notifications on a flaky link." - A 1-minute rate limiter keyed by event type + outbound tag, on both transports: `eventbus.NewRateLimiter(1 * time.Minute)` at `internal/web/service/tgbot/tgbot_event.go:28` (applied at `:37`) and `internal/web/service/email/subscriber.go:28` (applied at `:41`). The message bodies are at `internal/web/service/tgbot/tgbot_event.go:65-87` (Telegram, includes tag, error and delay) and `internal/web/service/email/subscriber.go:92-113` (HTML email). Docs: [Telegram bot → events](https://docs.sanaei.dev/docs/operations/telegram-bot) lists `outbound.down` / `outbound.up` and `tgEnabledEvents`. **What genuinely does not exist**, and is the only part of your request left open: there is no *balancer-level* event. The panel notifies per outbound tag, so on a failover you get "Outbound X is DOWN" — nothing names the balancer, and nothing says which `fallbackTag` took over. `fallbackTag` is stored and rendered (`frontend/src/schemas/xray.ts:137`) but never fed to the event bus; the only publishers of outbound events are `internal/web/service/xray_metrics.go:265` and `:281`. For flaky-server troubleshooting the per-tag down/up alert is usually the signal you want, but if a "balancer B switched to fallback F" message is specifically what you need, that part is a real gap and this issue is a reasonable place to track it. I have left it open with the `enhancement` label for that. Verdict: Already fixed (shipped for the per-outbound case; the balancer-level event is the remaining gap) The events landed in eec030f8 `feat(notifications): event bus architecture with Telegram and SMTP subscribers (#5326)`, first released in **v3.4.0**; the configurable failure threshold in 2b1308ca `feat(notifications): add a consecutive-failure threshold for outbound.down alerts (#5968)`, first released in **v3.6.0**. Both are in v3.7.0. Related, not duplicates: #6387, #6355, #6305. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@shlima commented on GitHub (Sep 6, 2026):

The solution described above does not work when the load balancer contains reverse VLESS connections.

<!-- gh-comment-id:5558302363 --> @shlima commented on GitHub (Sep 6, 2026): The solution described above does not work when the load balancer contains **reverse** VLESS connections.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4351
No description provided.