Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-03-17 19:07:49 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-03-17 19:07:49 +0300
commit96786c94189f3d2f3f04c1915529c786228bdf42 (patch)
tree879085e09a3cd485f3246f46be907fe77eb84a1a /web/job/check_cpu_usage.go
parentbc56e637376142c370c31b17558fc3778a863bd2 (diff)
alireza
Diffstat (limited to 'web/job/check_cpu_usage.go')
-rw-r--r--web/job/check_cpu_usage.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/web/job/check_cpu_usage.go b/web/job/check_cpu_usage.go
new file mode 100644
index 00000000..cfc86b60
--- /dev/null
+++ b/web/job/check_cpu_usage.go
@@ -0,0 +1,30 @@
+package job
+
+import (
+ "fmt"
+ "time"
+ "x-ui/web/service"
+
+ "github.com/shirou/gopsutil/v3/cpu"
+)
+
+type CheckCpuJob struct {
+ tgbotService service.Tgbot
+ settingService service.SettingService
+}
+
+func NewCheckCpuJob() *CheckCpuJob {
+ return new(CheckCpuJob)
+}
+
+// Here run is a interface method of Job interface
+func (j *CheckCpuJob) Run() {
+ threshold, _ := j.settingService.GetTgCpu()
+
+ // get latest status of server
+ percent, err := cpu.Percent(1*time.Second, false)
+ if err == nil && percent[0] > float64(threshold) {
+ msg := fmt.Sprintf("🔴 CPU usage %.2f%% is more than threshold %d%%", percent[0], threshold)
+ j.tgbotService.SendMsgToTgbotAdmins(msg)
+ }
+}