-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMemory.go
53 lines (46 loc) · 1.05 KB
/
Memory.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
package main
import (
"github.com/shirou/gopsutil/mem"
)
//SwapMemory 交换内存
//VirtualMemory 虚拟内存
//VirtualMemoryEx 虚拟交换内存
type Memory struct {
SwapMemory *mem.SwapMemoryStat `json:"swapMemory"`
VirtualMemory *mem.VirtualMemoryStat `json:"virtualMemory"`
VirtualMemoryEx *mem.VirtualMemoryExStat `json:"virtualMemoryEx"`
}
//获得内存有关信息
func GetVirtualMemInfo() *mem.VirtualMemoryStat {
memInfo, _ := mem.VirtualMemory()
return memInfo
}
func GetVirtualMemExInfo() *mem.VirtualMemoryExStat {
memInfo, _ := mem.VirtualMemoryEx()
return memInfo
}
func GetMemory() Memory {
swapInfo, err := mem.SwapMemory()
if err != nil {
panic(err)
}
memInfo, err := mem.VirtualMemory()
if err != nil {
panic(err)
}
memExinfo, err := mem.VirtualMemoryEx()
if err != nil {
panic(err)
}
memory := Memory{
SwapMemory: swapInfo,
VirtualMemory: memInfo,
VirtualMemoryEx: memExinfo,
}
return memory
}
//
//func main(){
// fmt.Println(GetVirtualMemExInfo())
// fmt.Println(GetVirtualMemInfo())
//}