-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_linux.go
74 lines (64 loc) · 1.37 KB
/
stats_linux.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
// stat_linux
// system stats aquisition function
// for Linux and *BSD with mounted procfs
package main
import (
proc "github.com/cespare/goproc"
// spew "github.com/davecgh/go-spew/spew"
)
/*
var (
CPUuser DeltaAcc
CPUsuser []DeltaAcc
CPUsys DeltaAcc
CPUssys []DeltaAcc
CPUidle DeltaAcc
CPUsidle []DeltaAcc)
*/
func (m *memData) Update() error {
t, err := proc.MemInfo()
if err != nil {
return err
}
m.memTotal = t["MemTotal"]
m.memFree = t["MemFree"]
m.memUse = m.memTotal - m.memFree
m.memPercent = int(m.memUse * 100 / m.memTotal)
m.swapTotal = t["SwapTotal"]
m.swapFree = t["SwapFree"]
m.swapUse = m.swapTotal - m.swapFree
m.swapPercent = int(m.swapUse * 100 / m.swapTotal)
return nil
}
func getifnum() (int, error) {
r, _, err := proc.NetDevStats()
if err != nil {
return 0, err
}
return len(r), nil
}
func (nd *netData) Setup() error {
r, t, err := proc.NetDevStats()
if err != nil {
return err
}
for key := range r {
nd.name = append(nd.name, key)
}
for i := 0; i < nd.size; i++ {
nd.downacc[i].Push(uint64(r[nd.name[i]]["bytes"]))
nd.upacc[i].Push(uint64(t[nd.name[i]]["bytes"]))
}
return nil
}
func (nd *netData) Update() error {
r, t, err := proc.NetDevStats()
if err != nil {
return err
}
for i, key := range nd.name {
nd.downacc[i].Push(uint64(r[key]["bytes"]))
nd.upacc[i].Push(uint64(t[key]["bytes"]))
}
return nil
}