@@ -23,9 +23,9 @@ func ParseNetstat(output string, mode string,
23
23
24
24
exists := make ([]string , 0 , len (lines )- 1 )
25
25
26
- columns := 6
27
- if mode == "ind " {
28
- columns = 10
26
+ columns := 9
27
+ if mode == "inb " {
28
+ columns = 6
29
29
}
30
30
for _ , line := range lines {
31
31
values := strings .Fields (line )
@@ -48,18 +48,23 @@ func ParseNetstat(output string, mode string,
48
48
49
49
parsed := make ([]uint64 , 0 , 8 )
50
50
var vv []string
51
- if mode == "inb" {
51
+ switch mode {
52
+ case "inb" :
52
53
vv = []string {
53
54
values [base + 3 ], // BytesRecv
54
55
values [base + 4 ], // BytesSent
55
56
}
56
- } else {
57
+ case "ind" :
57
58
vv = []string {
58
59
values [base + 3 ], // Ipkts
59
- values [base + 4 ], // Ierrs
60
+ values [base + 4 ], // Idrop
60
61
values [base + 5 ], // Opkts
62
+ values [base + 6 ], // Odrops
63
+ }
64
+ case "ine" :
65
+ vv = []string {
66
+ values [base + 4 ], // Ierrs
61
67
values [base + 6 ], // Oerrs
62
- values [base + 8 ], // Drops
63
68
}
64
69
}
65
70
for _ , target := range vv {
@@ -80,16 +85,19 @@ func ParseNetstat(output string, mode string,
80
85
if ! present {
81
86
n = IOCountersStat {Name : values [0 ]}
82
87
}
83
- if mode == "inb" {
88
+
89
+ switch mode {
90
+ case "inb" :
84
91
n .BytesRecv = parsed [0 ]
85
92
n .BytesSent = parsed [1 ]
86
- } else {
93
+ case "ind" :
87
94
n .PacketsRecv = parsed [0 ]
88
- n .Errin = parsed [1 ]
95
+ n .Dropin = parsed [1 ]
89
96
n .PacketsSent = parsed [2 ]
90
- n .Errout = parsed [3 ]
91
- n .Dropin = parsed [4 ]
92
- n .Dropout = parsed [4 ]
97
+ n .Dropout = parsed [3 ]
98
+ case "ine" :
99
+ n .Errin = parsed [0 ]
100
+ n .Errout = parsed [1 ]
93
101
}
94
102
95
103
iocs [n .Name ] = n
@@ -114,6 +122,10 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
114
122
if err != nil {
115
123
return nil , err
116
124
}
125
+ out3 , err := invoke .CommandWithContext (ctx , netstat , "-ine" )
126
+ if err != nil {
127
+ return nil , err
128
+ }
117
129
iocs := make (map [string ]IOCountersStat )
118
130
119
131
lines := strings .Split (string (out ), "\n " )
@@ -127,6 +139,10 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
127
139
if err != nil {
128
140
return nil , err
129
141
}
142
+ err = ParseNetstat (string (out3 ), "ine" , iocs )
143
+ if err != nil {
144
+ return nil , err
145
+ }
130
146
131
147
for _ , ioc := range iocs {
132
148
ret = append (ret , ioc )
0 commit comments