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
// TimeInfo 系统时间信息
TimeInfo() map[string]string
TimeInfo() map[string]any
// MemoryInfo 内存信息
MemoryInfo() map[string]any

View File

@@ -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,
}