mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 13:14:11 +00:00
- Update go.mod module path from mhsanaei/3x-ui/v3 to saeederamy/3x-ui/v3 - Update all 73 Go files' import paths accordingly - Fix README.fa_IR.md install command to point to fork's main branch The fork was referencing the original repo's module path in go.mod and all Go source imports, making it dependent on MHSanaei's namespace at build time. https://claude.ai/code/session_01M6d5atbWjuLTj6UwRHoK5m
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package job
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/saeederamy/3x-ui/v3/web/service"
|
|
|
|
"github.com/shirou/gopsutil/v4/cpu"
|
|
)
|
|
|
|
// CheckCpuJob monitors CPU usage and sends Telegram notifications when usage exceeds the configured threshold.
|
|
type CheckCpuJob struct {
|
|
tgbotService service.Tgbot
|
|
settingService service.SettingService
|
|
}
|
|
|
|
// NewCheckCpuJob creates a new CPU monitoring job instance.
|
|
func NewCheckCpuJob() *CheckCpuJob {
|
|
return new(CheckCpuJob)
|
|
}
|
|
|
|
// Run checks CPU usage over the last minute and sends a Telegram alert if it exceeds the threshold.
|
|
func (j *CheckCpuJob) Run() {
|
|
threshold, err := j.settingService.GetTgCpu()
|
|
if err != nil || threshold <= 0 {
|
|
// If threshold cannot be retrieved or is not set, skip sending notifications
|
|
return
|
|
}
|
|
|
|
// get latest status of server
|
|
percent, err := cpu.Percent(1*time.Minute, false)
|
|
if err == nil && percent[0] > float64(threshold) {
|
|
msg := j.tgbotService.I18nBot("tgbot.messages.cpuThreshold",
|
|
"Percent=="+strconv.FormatFloat(percent[0], 'f', 2, 64),
|
|
"Threshold=="+strconv.Itoa(threshold))
|
|
|
|
j.tgbotService.SendMsgToTgbotAdmins(msg)
|
|
}
|
|
}
|