|
package system |
|
|
|
import ( |
|
"fmt" |
|
"runtime" |
|
"time" |
|
|
|
"github.com/GoAdminGroup/go-admin/modules/config" |
|
"github.com/GoAdminGroup/go-admin/modules/language" |
|
"github.com/GoAdminGroup/go-admin/modules/utils" |
|
) |
|
|
|
var ( |
|
startTime = time.Now() |
|
) |
|
|
|
type AppStatus struct { |
|
Uptime string |
|
NumGoroutine int |
|
|
|
|
|
MemAllocated string |
|
MemTotal string |
|
MemSys string |
|
Lookups uint64 |
|
MemMallocs uint64 |
|
MemFrees uint64 |
|
|
|
|
|
HeapAlloc string |
|
HeapSys string |
|
HeapIdle string |
|
HeapInuse string |
|
HeapReleased string |
|
HeapObjects uint64 |
|
|
|
|
|
|
|
|
|
StackInuse string |
|
StackSys string |
|
MSpanInuse string |
|
MSpanSys string |
|
MCacheInuse string |
|
MCacheSys string |
|
BuckHashSys string |
|
GCSys string |
|
OtherSys string |
|
|
|
|
|
NextGC string |
|
LastGC string |
|
PauseTotalNs string |
|
PauseNs string |
|
NumGC uint32 |
|
} |
|
|
|
func GetAppStatus() AppStatus { |
|
var app AppStatus |
|
app.Uptime = utils.TimeSincePro(startTime, language.Lang[config.GetLanguage()]) |
|
|
|
m := new(runtime.MemStats) |
|
runtime.ReadMemStats(m) |
|
app.NumGoroutine = runtime.NumGoroutine() |
|
|
|
app.MemAllocated = utils.FileSize(m.Alloc) |
|
app.MemTotal = utils.FileSize(m.TotalAlloc) |
|
app.MemSys = utils.FileSize(m.Sys) |
|
app.Lookups = m.Lookups |
|
app.MemMallocs = m.Mallocs |
|
app.MemFrees = m.Frees |
|
|
|
app.HeapAlloc = utils.FileSize(m.HeapAlloc) |
|
app.HeapSys = utils.FileSize(m.HeapSys) |
|
app.HeapIdle = utils.FileSize(m.HeapIdle) |
|
app.HeapInuse = utils.FileSize(m.HeapInuse) |
|
app.HeapReleased = utils.FileSize(m.HeapReleased) |
|
app.HeapObjects = m.HeapObjects |
|
|
|
app.StackInuse = utils.FileSize(m.StackInuse) |
|
app.StackSys = utils.FileSize(m.StackSys) |
|
app.MSpanInuse = utils.FileSize(m.MSpanInuse) |
|
app.MSpanSys = utils.FileSize(m.MSpanSys) |
|
app.MCacheInuse = utils.FileSize(m.MCacheInuse) |
|
app.MCacheSys = utils.FileSize(m.MCacheSys) |
|
app.BuckHashSys = utils.FileSize(m.BuckHashSys) |
|
app.GCSys = utils.FileSize(m.GCSys) |
|
app.OtherSys = utils.FileSize(m.OtherSys) |
|
|
|
app.NextGC = utils.FileSize(m.NextGC) |
|
app.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000) |
|
app.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000) |
|
app.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000) |
|
app.NumGC = m.NumGC |
|
|
|
return app |
|
} |
|
|
|
type SysStatus struct { |
|
CpuLogicalCore int |
|
CpuCore int |
|
OSPlatform string |
|
OSFamily string |
|
OSVersion string |
|
Load1 float64 |
|
Load5 float64 |
|
Load15 float64 |
|
MemTotal string |
|
MemAvailable string |
|
MemUsed string |
|
} |
|
|