-
Notifications
You must be signed in to change notification settings - Fork 83
/
main_test.go
108 lines (88 loc) · 2.16 KB
/
main_test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package nux
import (
"fmt"
"testing"
)
func TestMetrics(t *testing.T) {
fmt.Println("======kernel======")
fmt.Print("KernelMaxFiles:")
fmt.Println(KernelMaxFiles())
fmt.Print("KernelAllocateFiles:")
fmt.Println(KernelAllocateFiles())
fmt.Print("KernelMaxProc:")
fmt.Println(KernelMaxProc())
fmt.Print("KernelHostname:")
fmt.Println(KernelHostname())
fmt.Println("======loadavg======")
fmt.Print("LoadAvg:")
fmt.Println(LoadAvg())
fmt.Println("======cpuinfo======")
fmt.Print("NumCpu:")
fmt.Println(NumCpu())
fmt.Print("CpuMHz:")
fmt.Println(CpuMHz())
fmt.Println("======cpustat======")
if ps, err := CurrentProcStat(); err != nil {
fmt.Println("error:", err)
} else {
fmt.Print("CPU :")
fmt.Println(ps.Cpu)
for i, o := range ps.Cpus {
fmt.Printf("CPU%d:", i)
fmt.Println(o)
}
}
fmt.Println("======dfstat======")
if L, err := ListMountPoint(); err != nil {
fmt.Println("error:", err)
} else {
for _, arr := range L {
fmt.Println(BuildDeviceUsage(arr[0], arr[1], arr[2]))
}
}
fmt.Println("======NetIfs======")
if L, err := NetIfs([]string{}); err != nil {
fmt.Println("error:", err)
} else {
for _, i := range L {
fmt.Println(i)
}
}
fmt.Println("======ListDiskStats======")
if L, err := ListDiskStats(); err != nil {
fmt.Println("error:", err)
} else {
for _, i := range L {
fmt.Println(i)
}
}
fmt.Println("======MemInfo:======")
fmt.Println(MemInfo())
fmt.Println("=========TcpExt:=======")
fmt.Println(Netstat("TcpExt"))
fmt.Println("=========IpExt:=======")
fmt.Println(Netstat("IpExt"))
fmt.Println("=========ListeningPorts:=======")
fmt.Println(ListeningPorts())
fmt.Println("=========Procs:=======")
if L, err := AllProcs(); err != nil {
fmt.Println("error:", err)
} else {
for i, item := range L {
fmt.Println(item)
if i == 10 {
fmt.Println("and more...")
break
}
}
}
fmt.Println("==============ss -s===============")
fmt.Println(SocketStatSummary())
fmt.Println("=============uptime:==============")
days, hours, mins, err := SystemUptime()
if err != nil {
fmt.Println("error:", err)
} else {
fmt.Printf("%d days, %d hours, %d mins\n", days, hours, mins)
}
}