This commit is contained in:
2023-10-24 10:30:42 +08:00
2 changed files with 9 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ type ISystemInfo interface {
SystemInfo() map[string]any SystemInfo() map[string]any
// TimeInfo 系统时间信息 // TimeInfo 系统时间信息
TimeInfo() map[string]string TimeInfo() map[string]any
// MemoryInfo 内存信息 // MemoryInfo 内存信息
MemoryInfo() map[string]any MemoryInfo() map[string]any

View File

@@ -29,7 +29,10 @@ func (s *SystemInfoImpl) SystemInfo() map[string]any {
if err != nil { if err != nil {
info.Platform = err.Error() info.Platform = err.Error()
} }
bootTime := time.Since(time.Unix(int64(info.BootTime), 0)).String() // 获取主机运行时间
bootTime := time.Since(time.Unix(int64(info.BootTime), 0)).Seconds()
// 获取程序运行时间
runTime := time.Since(config.RunTime()).Abs().Seconds()
return map[string]any{ return map[string]any{
"platform": info.Platform, "platform": info.Platform,
"platformVersion": info.PlatformVersion, "platformVersion": info.PlatformVersion,
@@ -37,28 +40,26 @@ func (s *SystemInfoImpl) SystemInfo() map[string]any {
"archVersion": info.KernelVersion, "archVersion": info.KernelVersion,
"os": info.OS, "os": info.OS,
"hostname": info.Hostname, "hostname": info.Hostname,
"bootTime": bootTime, "bootTime": int64(bootTime),
"processId": os.Getpid(), "processId": os.Getpid(),
"runArch": runtime.GOARCH, "runArch": runtime.GOARCH,
"runVersion": runtime.Version(), "runVersion": runtime.Version(),
"runTime": int64(runTime),
} }
} }
// TimeInfo 系统时间信息 // TimeInfo 系统时间信息
func (s *SystemInfoImpl) TimeInfo() map[string]string { func (s *SystemInfoImpl) TimeInfo() map[string]any {
now := time.Now() now := time.Now()
// 获取当前时间 // 获取当前时间
current := now.Format("2006-01-02 15:04:05") current := now.Format("2006-01-02 15:04:05")
// 获取程序运行时间
uptime := time.Since(config.RunTime()).String()
// 获取时区 // 获取时区
timezone := now.Format("-0700 MST") timezone := now.Format("-0700 MST")
// 获取时区名称 // 获取时区名称
timezoneName := now.Format("MST") timezoneName := now.Format("MST")
return map[string]string{ return map[string]any{
"current": current, "current": current,
"uptime": uptime,
"timezone": timezone, "timezone": timezone,
"timezoneName": timezoneName, "timezoneName": timezoneName,
} }