/
all.go
81 lines (72 loc) · 2.06 KB
/
all.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package info
import (
"github.com/kyaxcorp/go-core/core/bootstrap"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
"os"
"runtime"
"time"
)
// TODO: should be moved in helpers or smth
type SystemStatus struct {
PID int
ExecutableLocation string
UserID int
GroupID int
Started time.Time
RunningTimeSeconds float64
NrOfRunningGoroutines int
MemStats map[string]interface{}
NrOfCPUUsed int
NrOfCGOCalls int64
CPUInfo CPUInfoStr
DisksInfo map[string]interface{}
NetInfo map[string]interface{}
HostInfo *host.InfoStat
VirtualMemoryStat *mem.VirtualMemoryStat
}
func GetSystemStatus() SystemStatus {
b := bootstrap.GetProcessBootstrap()
executablePath, _ := os.Executable()
cpuInfoChan := make(chan CPUInfoStr)
processMemInfoChan := make(chan map[string]interface{})
memInfoChan := make(chan *mem.VirtualMemoryStat)
hostInfoChan := make(chan *host.InfoStat)
disksInfoChan := make(chan map[string]interface{})
netInfoChan := make(chan map[string]interface{})
go func() {
cpuInfoChan <- GetCPUInfo()
}()
go func() {
processMemInfoChan <- GetProcessMemoryInfo()
}()
go func() {
memInfoChan <- GetMemoryInfo()
}()
go func() {
hostInfoChan <- GetHostInfo()
}()
go func() {
disksInfoChan <- GetDisksInfo()
}()
go func() {
netInfoChan <- GetNetInfo()
}()
return SystemStatus{
PID: os.Getpid(),
ExecutableLocation: executablePath,
UserID: os.Getuid(),
GroupID: os.Getgid(),
Started: b.GetStartTime(),
RunningTimeSeconds: b.GetRunningTime().Seconds(),
NrOfRunningGoroutines: runtime.NumGoroutine(),
NrOfCPUUsed: runtime.NumCPU(),
NrOfCGOCalls: runtime.NumCgoCall(),
MemStats: <-processMemInfoChan,
CPUInfo: <-cpuInfoChan,
VirtualMemoryStat: <-memInfoChan,
HostInfo: <-hostInfoChan,
DisksInfo: <-disksInfoChan,
NetInfo: <-netInfoChan,
}
}