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
36 lines
826 B
Go
36 lines
826 B
Go
package job
|
|
|
|
import (
|
|
"github.com/mhsanaei/3x-ui/v3/internal/eventbus"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
|
|
|
|
"github.com/shirou/gopsutil/v4/mem"
|
|
)
|
|
|
|
// CheckMemJob monitors memory usage and publishes events when threshold is exceeded.
|
|
type CheckMemJob struct {
|
|
settingService service.SettingService
|
|
}
|
|
|
|
// NewCheckMemJob creates a new memory monitoring job instance.
|
|
func NewCheckMemJob() *CheckMemJob {
|
|
return new(CheckMemJob)
|
|
}
|
|
|
|
// Run checks memory usage and publishes a memory.high event with raw metric data.
|
|
func (j *CheckMemJob) Run() {
|
|
memInfo, err := mem.VirtualMemory()
|
|
if err != nil || memInfo == nil {
|
|
return
|
|
}
|
|
|
|
if EventBus != nil {
|
|
EventBus.Publish(eventbus.Event{
|
|
Type: eventbus.EventMemoryHigh,
|
|
Data: &eventbus.SystemMetricData{
|
|
Percent: memInfo.UsedPercent,
|
|
},
|
|
})
|
|
}
|
|
}
|