mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-28 00:24:19 +00:00
891d3a8759
* feat(memory): add memory threshold alerts
Add memory (RAM) threshold alerts following the same architecture as
CPU alerts: CheckMemJob with @every 1m cadence, memoryAlarmWanted gate,
tgMemory/smtpMemory per-subscriber settings (default 80%), EventBusCheckboxes
with inline threshold input, i18n for en-US/ru-RU with English defaults.
# Conflicts:
# internal/web/translation/ar-EG.json
# internal/web/translation/es-ES.json
# internal/web/translation/fa-IR.json
# internal/web/translation/id-ID.json
# internal/web/translation/ja-JP.json
# internal/web/translation/pt-BR.json
# internal/web/translation/ru-RU.json
# internal/web/translation/tr-TR.json
# internal/web/translation/uk-UA.json
# internal/web/translation/vi-VN.json
# internal/web/translation/zh-CN.json
# internal/web/translation/zh-TW.json
* fix: address code review findings for memory alerts
- Remove dead settingService field from CheckMemJob
- Fix cpuThreshold double-emoji in 12 locale files (code prepends 🔴)
- Align TgCpu/TgMemory fields in entity.go
- Add missing SetTgMemory function
* fix: restore settingService in CheckMemJob for consistency with CheckCpuJob
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package eventbus
|
|
|
|
import "time"
|
|
|
|
// EventType identifies the kind of event flowing through the bus.
|
|
type EventType string
|
|
|
|
const (
|
|
// Outbound health (observatory-driven)
|
|
EventOutboundDown EventType = "outbound.down"
|
|
EventOutboundUp EventType = "outbound.up"
|
|
|
|
// Xray core (local)
|
|
EventXrayCrash EventType = "xray.crash"
|
|
|
|
// Node health (heartbeat-driven)
|
|
EventNodeDown EventType = "node.down"
|
|
EventNodeUp EventType = "node.up"
|
|
|
|
// System health
|
|
EventCPUHigh EventType = "cpu.high"
|
|
EventMemoryHigh EventType = "memory.high"
|
|
|
|
// Security
|
|
EventLoginAttempt EventType = "login.attempt"
|
|
)
|
|
|
|
// Event is the unit of information flowing through the bus.
|
|
type Event struct {
|
|
Type EventType
|
|
Source string // outbound tag, node name, client email, IP, etc.
|
|
Data any // event-specific payload, may be nil
|
|
Timestamp time.Time // when the event was detected
|
|
}
|
|
|
|
// OutboundHealthData carries observatory details for outbound events.
|
|
type OutboundHealthData struct {
|
|
Delay int64 // last measured delay in ms, 0 if unknown
|
|
Error string // last error if probe failed, empty if up
|
|
}
|
|
|
|
// NodeHealthData carries heartbeat details for node events.
|
|
type NodeHealthData struct {
|
|
NodeId int
|
|
LatencyMs int
|
|
CpuPct float64
|
|
MemPct float64
|
|
XrayState string // "running", "stopped", etc.
|
|
XrayError string
|
|
}
|
|
|
|
// LoginEventData carries login attempt details.
|
|
type LoginEventData struct {
|
|
Username string
|
|
IP string
|
|
Time string
|
|
Status string // "success" or "fail"
|
|
Reason string
|
|
}
|
|
|
|
// SystemMetricData carries raw system metric values for threshold-based events.
|
|
type SystemMetricData struct {
|
|
Percent float64 // current usage percentage
|
|
Threshold int // configured threshold
|
|
}
|