forked from xiaokangwang/AndroidLibV2ray
-
Notifications
You must be signed in to change notification settings - Fork 3
/
stat.go
64 lines (58 loc) · 1.47 KB
/
stat.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
package libv2ray
import (
"io/ioutil"
"os"
"strconv"
"strings"
)
type InterfaceInfo struct {
RxByte, RxPacket, TxByte, TxPacket int
}
func (sc *StatControler) CollectInterfaceInfo() error {
f, err := os.Open("/proc/net/dev")
if err != nil {
return err
}
d, _ := ioutil.ReadAll(f)
s := strings.Split(strings.TrimSpace(string(d)), "\n")
for _, scc := range s {
subsc := strings.Split(strings.TrimSpace(scc), " ")
//log.Println("CollectInterfaceInfo Examing ", scc)
if subsc[0] == sc.InterfaceTarget {
subscclean := make([]string, 0, 5)
for _, csubsc := range subsc {
if csubsc != "" {
subscclean = append(subscclean, csubsc)
}
}
//spew.Dump(subscclean)
var infoCandidcate InterfaceInfo
var convError error
infoCandidcate.RxByte, convError = strconv.Atoi(subscclean[1])
if convError != nil {
return convError
}
infoCandidcate.RxPacket, convError = strconv.Atoi(subscclean[2])
if convError != nil {
return convError
}
infoCandidcate.TxByte, convError = strconv.Atoi(subscclean[9])
if convError != nil {
return convError
}
infoCandidcate.TxPacket, convError = strconv.Atoi(subscclean[10])
if convError != nil {
return convError
}
sc.CollectedInterfaceInfo = &infoCandidcate
}
}
return nil
}
func (v *V2RayPoint) GetStatControler() *StatControler {
return &StatControler{InterfaceTarget: "tun0:"}
}
type StatControler struct {
InterfaceTarget string
CollectedInterfaceInfo *InterfaceInfo
}