mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-10-27 02:24:40 +00:00 
			
		
		
		
	Update tgbot.go
This commit is contained in:
		
							parent
							
								
									92a26f1773
								
							
						
					
					
						commit
						5348a6db12
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		|  | @ -17,6 +17,8 @@ import ( | ||||||
| 	"x-ui/xray" | 	"x-ui/xray" | ||||||
| 
 | 
 | ||||||
| 	"github.com/mymmrac/telego" | 	"github.com/mymmrac/telego" | ||||||
|  | 	"github.com/shirou/gopsutil/cpu" | ||||||
|  | 	"github.com/shirou/gopsutil/disk" | ||||||
| 	th "github.com/mymmrac/telego/telegohandler" | 	th "github.com/mymmrac/telego/telegohandler" | ||||||
| 	tu "github.com/mymmrac/telego/telegoutil" | 	tu "github.com/mymmrac/telego/telegoutil" | ||||||
| ) | ) | ||||||
|  | @ -621,6 +623,33 @@ func (t *Tgbot) getServerUsage() string { | ||||||
| 		info += t.I18nBot("tgbot.messages.ipv6", "IPv6=="+ipv6) | 		info += t.I18nBot("tgbot.messages.ipv6", "IPv6=="+ipv6) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// get CPU usage
 | ||||||
|  | 	percent, err := cpu.Percent(0, false) | ||||||
|  | 	if err != nil { | ||||||
|  | 		logger.Error("cpu.Percent failed, err: ", err.Error()) | ||||||
|  | 		info += t.I18nBot("tgbot.messages.cpuUsage", "CPU Usage=="+t.I18nBot("tgbot.unknown")) | ||||||
|  | 	} else { | ||||||
|  | 		info += t.I18nBot("tgbot.messages.cpuUsage", "CPU Usage=="+strconv.FormatFloat(percent[0], 'f', 2, 64)+"%") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// get CPU info
 | ||||||
|  | 	cpuInfo, err := cpu.Info() | ||||||
|  | 	if err != nil { | ||||||
|  | 		logger.Error("cpu.Info failed, err: ", err.Error()) | ||||||
|  | 		info += t.I18nBot("tgbot.messages.cpuInfo", "CPU Info=="+t.I18nBot("tgbot.unknown")) | ||||||
|  | 	} else { | ||||||
|  | 		info += t.I18nBot("tgbot.messages.cpuInfo", "CPU Model=="+cpuInfo[0].ModelName) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// get disk usage
 | ||||||
|  | 	diskStat, err := disk.Usage("/") | ||||||
|  | 	if err != nil { | ||||||
|  | 		logger.Error("disk.Usage failed, err: ", err.Error()) | ||||||
|  | 		info += t.I18nBot("tgbot.messages.diskUsage", "Disk Usage=="+t.I18nBot("tgbot.unknown")) | ||||||
|  | 	} else { | ||||||
|  | 		info += t.I18nBot("tgbot.messages.diskUsage", "Disk Usage=="+strconv.FormatUint(diskStat.Used/1024/1024/1024, 10)+"/"+strconv.FormatUint(diskStat.Total/1024/1024/1024, 10)+"GB") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// get latest status of server
 | 	// get latest status of server
 | ||||||
| 	t.lastStatus = t.serverService.GetStatus(t.lastStatus) | 	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")) | 	info += t.I18nBot("tgbot.messages.serverUpTime", "UpTime=="+strconv.FormatUint(t.lastStatus.Uptime/86400, 10), "Unit=="+t.I18nBot("tgbot.days")) | ||||||
|  | @ -633,6 +662,8 @@ func (t *Tgbot) getServerUsage() string { | ||||||
| 	return info | 	return info | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| func (t *Tgbot) UserLoginNotify(username string, ip string, time string, status LoginStatus) { | func (t *Tgbot) UserLoginNotify(username string, ip string, time string, status LoginStatus) { | ||||||
| 	if !t.IsRunning() { | 	if !t.IsRunning() { | ||||||
| 		return | 		return | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 quydang
						quydang