| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | 
							- package systeminfo
 
- import (
 
- 	"fmt"
 
- 	"runtime"
 
- 	"time"
 
- )
 
- var initTime = time.Now()
 
- type SystemInfo struct {
 
- 	Uptime       string
 
- 	NumGoroutine int
 
- 	// General statistics.
 
- 	MemAllocated string // bytes allocated and still in use
 
- 	MemTotal     string // bytes allocated (even if freed)
 
- 	MemSys       string // bytes obtained from system (sum of XxxSys below)
 
- 	Lookups      uint64 // number of pointer lookups
 
- 	MemMallocs   uint64 // number of mallocs
 
- 	MemFrees     uint64 // number of frees
 
- 	// Main allocation heap statistics.
 
- 	HeapAlloc    string // bytes allocated and still in use
 
- 	HeapSys      string // bytes obtained from system
 
- 	HeapIdle     string // bytes in idle spans
 
- 	HeapInuse    string // bytes in non-idle span
 
- 	HeapReleased string // bytes released to the OS
 
- 	HeapObjects  uint64 // total number of allocated objects
 
- 	// Low-level fixed-size structure allocator statistics.
 
- 	//	Inuse is bytes used now.
 
- 	//	Sys is bytes obtained from system.
 
- 	StackInuse  string // bootstrap stacks
 
- 	StackSys    string
 
- 	MSpanInuse  string // mspan structures
 
- 	MSpanSys    string
 
- 	MCacheInuse string // mcache structures
 
- 	MCacheSys   string
 
- 	BuckHashSys string // profiling bucket hash table
 
- 	GCSys       string // GC metadata
 
- 	OtherSys    string // other system allocations
 
- 	// Garbage collector statistics.
 
- 	NextGC       string // next run in HeapAlloc time (bytes)
 
- 	LastGC       string // last run in absolute time (ns)
 
- 	PauseTotalNs string
 
- 	PauseNs      string // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256]
 
- 	NumGC        uint32
 
- }
 
- func GetSystemInfo() (sysStatus *SystemInfo) {
 
- 	sysStatus = &SystemInfo{}
 
- 	sysStatus.Uptime = TimeSincePro(initTime)
 
- 	m := new(runtime.MemStats)
 
- 	runtime.ReadMemStats(m)
 
- 	sysStatus.NumGoroutine = runtime.NumGoroutine()
 
- 	sysStatus.MemAllocated = FileSize(int64(m.Alloc))
 
- 	sysStatus.MemTotal = FileSize(int64(m.TotalAlloc))
 
- 	sysStatus.MemSys = FileSize(int64(m.Sys))
 
- 	sysStatus.Lookups = m.Lookups
 
- 	sysStatus.MemMallocs = m.Mallocs
 
- 	sysStatus.MemFrees = m.Frees
 
- 	sysStatus.HeapAlloc = FileSize(int64(m.HeapAlloc))
 
- 	sysStatus.HeapSys = FileSize(int64(m.HeapSys))
 
- 	sysStatus.HeapIdle = FileSize(int64(m.HeapIdle))
 
- 	sysStatus.HeapInuse = FileSize(int64(m.HeapInuse))
 
- 	sysStatus.HeapReleased = FileSize(int64(m.HeapReleased))
 
- 	sysStatus.HeapObjects = m.HeapObjects
 
- 	sysStatus.StackInuse = FileSize(int64(m.StackInuse))
 
- 	sysStatus.StackSys = FileSize(int64(m.StackSys))
 
- 	sysStatus.MSpanInuse = FileSize(int64(m.MSpanInuse))
 
- 	sysStatus.MSpanSys = FileSize(int64(m.MSpanSys))
 
- 	sysStatus.MCacheInuse = FileSize(int64(m.MCacheInuse))
 
- 	sysStatus.MCacheSys = FileSize(int64(m.MCacheSys))
 
- 	sysStatus.BuckHashSys = FileSize(int64(m.BuckHashSys))
 
- 	sysStatus.GCSys = FileSize(int64(m.GCSys))
 
- 	sysStatus.OtherSys = FileSize(int64(m.OtherSys))
 
- 	sysStatus.NextGC = FileSize(int64(m.NextGC))
 
- 	sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
 
- 	sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
 
- 	sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
 
- 	sysStatus.NumGC = m.NumGC
 
- 	return
 
- }
 
 
  |