diff --git a/web/service/tgbot.go b/web/service/tgbot.go index a852a847..aaf6752f 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -17,8 +17,6 @@ import ( "x-ui/xray" "github.com/mymmrac/telego" - "github.com/shirou/gopsutil/cpu" - "github.com/shirou/gopsutil/disk" th "github.com/mymmrac/telego/telegohandler" tu "github.com/mymmrac/telego/telegoutil" ) @@ -590,30 +588,6 @@ func (t *Tgbot) SendBackupToAdmins() { t.sendBackup(int64(adminId)) } } -// Get CPU Info -func getCPUInfo() (string, error) { - infoStat, err := cpu.Info() - if err != nil { - return "", err - } - return fmt.Sprintf("CPU Info: %v", infoStat[0]), nil -} -// Get disk usage -func getDiskUsage() (string, error) { - usageStat, err := disk.Usage("/") - if err != nil { - return "", err - } - return fmt.Sprintf("Disk Usage: %v", usageStat), nil -} -// Get CPU usage -func getCPUUsage() (string, error) { - percent, err := cpu.Percent(time.Second, false) - if err != nil { - return "", err - } - return fmt.Sprintf("CPU Usage: %.2f%%", percent[0]), nil -} func (t *Tgbot) getServerUsage() string { info, ipv4, ipv6 := "", "", "" @@ -646,6 +620,7 @@ func (t *Tgbot) getServerUsage() string { info += t.I18nBot("tgbot.messages.ipv4", "IPv4=="+ipv4) info += t.I18nBot("tgbot.messages.ipv6", "IPv6=="+ipv6) } + // get latest status of server t.lastStatus = t.serverService.GetStatus(t.lastStatus) info += t.I18nBot("tgbot.messages.serverUpTime", "UpTime=="+strconv.FormatUint(t.lastStatus.Uptime/86400, 10), "Unit=="+t.I18nBot("tgbot.days")) @@ -655,29 +630,6 @@ func (t *Tgbot) getServerUsage() string { info += t.I18nBot("tgbot.messages.udpCount", "Count=="+strconv.Itoa(t.lastStatus.UdpCount)) info += t.I18nBot("tgbot.messages.traffic", "Total=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent+t.lastStatus.NetTraffic.Recv)), "Upload=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent)), "Download=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Recv))) info += t.I18nBot("tgbot.messages.xrayStatus", "State=="+fmt.Sprint(t.lastStatus.Xray.State)) - // get CPU info - cpuInfo, err := getCPUInfo() - if err != nil { - logger.Error("Error getting CPU info: ", err) - } else { - info += t.I18nBot("tgbot.messages.cpuInfo", "CPU Info=="+cpuInfo) - } - - // get CPU usage - cpuUsage, err := getCPUUsage() - if err != nil { - logger.Error("Error getting CPU usage: ", err) - } else { - info += t.I18nBot("tgbot.messages.cpuUsage", "CPU Usage=="+cpuUsage) - } - - // get disk usage - diskUsage, err := getDiskUsage() - if err != nil { - logger.Error("Error getting disk usage: ", err) - } else { - info += t.I18nBot("tgbot.messages.diskUsage", "Disk Usage=="+diskUsage) - } return info }