From 0ed658aecdc4f9510783914b512b77ec93a326d7 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 23 Oct 2023 19:16:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BB=E6=9C=BA=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=A4=A9=E6=97=B6?= =?UTF-8?q?=E5=88=86=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/monitor/service/system_info.go | 2 +- src/modules/monitor/service/system_info.impl.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/modules/monitor/service/system_info.go b/src/modules/monitor/service/system_info.go index a6e9a51d..1f3fbdc9 100644 --- a/src/modules/monitor/service/system_info.go +++ b/src/modules/monitor/service/system_info.go @@ -6,7 +6,7 @@ type ISystemInfo interface { SystemInfo() map[string]any // TimeInfo 系统时间信息 - TimeInfo() map[string]string + TimeInfo() map[string]any // MemoryInfo 内存信息 MemoryInfo() map[string]any diff --git a/src/modules/monitor/service/system_info.impl.go b/src/modules/monitor/service/system_info.impl.go index e9aed318..4747ea3e 100644 --- a/src/modules/monitor/service/system_info.impl.go +++ b/src/modules/monitor/service/system_info.impl.go @@ -29,7 +29,10 @@ func (s *SystemInfoImpl) SystemInfo() map[string]any { if err != nil { 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{ "platform": info.Platform, "platformVersion": info.PlatformVersion, @@ -37,28 +40,26 @@ func (s *SystemInfoImpl) SystemInfo() map[string]any { "archVersion": info.KernelVersion, "os": info.OS, "hostname": info.Hostname, - "bootTime": bootTime, + "bootTime": int64(bootTime), "processId": os.Getpid(), "runArch": runtime.GOARCH, "runVersion": runtime.Version(), + "runTime": int64(runTime), } } // TimeInfo 系统时间信息 -func (s *SystemInfoImpl) TimeInfo() map[string]string { +func (s *SystemInfoImpl) TimeInfo() map[string]any { now := time.Now() // 获取当前时间 current := now.Format("2006-01-02 15:04:05") - // 获取程序运行时间 - uptime := time.Since(config.RunTime()).String() // 获取时区 timezone := now.Format("-0700 MST") // 获取时区名称 timezoneName := now.Format("MST") - return map[string]string{ + return map[string]any{ "current": current, - "uptime": uptime, "timezone": timezone, "timezoneName": timezoneName, }