Skip to content

Commit 80895ea

Browse files
authored
Merge pull request #1621 from amarinderca/patch-1
Update net_openbsd.go to correctly parse netstat output on obsd
2 parents 0dd1ffd + 6311a84 commit 80895ea

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

net/net_openbsd.go

+29-13
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func ParseNetstat(output string, mode string,
2323

2424
exists := make([]string, 0, len(lines)-1)
2525

26-
columns := 6
27-
if mode == "ind" {
28-
columns = 10
26+
columns := 9
27+
if mode == "inb" {
28+
columns = 6
2929
}
3030
for _, line := range lines {
3131
values := strings.Fields(line)
@@ -48,18 +48,23 @@ func ParseNetstat(output string, mode string,
4848

4949
parsed := make([]uint64, 0, 8)
5050
var vv []string
51-
if mode == "inb" {
51+
switch mode {
52+
case "inb":
5253
vv = []string{
5354
values[base+3], // BytesRecv
5455
values[base+4], // BytesSent
5556
}
56-
} else {
57+
case "ind":
5758
vv = []string{
5859
values[base+3], // Ipkts
59-
values[base+4], // Ierrs
60+
values[base+4], // Idrop
6061
values[base+5], // Opkts
62+
values[base+6], // Odrops
63+
}
64+
case "ine":
65+
vv = []string{
66+
values[base+4], // Ierrs
6167
values[base+6], // Oerrs
62-
values[base+8], // Drops
6368
}
6469
}
6570
for _, target := range vv {
@@ -80,16 +85,19 @@ func ParseNetstat(output string, mode string,
8085
if !present {
8186
n = IOCountersStat{Name: values[0]}
8287
}
83-
if mode == "inb" {
88+
89+
switch mode {
90+
case "inb":
8491
n.BytesRecv = parsed[0]
8592
n.BytesSent = parsed[1]
86-
} else {
93+
case "ind":
8794
n.PacketsRecv = parsed[0]
88-
n.Errin = parsed[1]
95+
n.Dropin = parsed[1]
8996
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]
93101
}
94102

95103
iocs[n.Name] = n
@@ -114,6 +122,10 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
114122
if err != nil {
115123
return nil, err
116124
}
125+
out3, err := invoke.CommandWithContext(ctx, netstat, "-ine")
126+
if err != nil {
127+
return nil, err
128+
}
117129
iocs := make(map[string]IOCountersStat)
118130

119131
lines := strings.Split(string(out), "\n")
@@ -127,6 +139,10 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
127139
if err != nil {
128140
return nil, err
129141
}
142+
err = ParseNetstat(string(out3), "ine", iocs)
143+
if err != nil {
144+
return nil, err
145+
}
130146

131147
for _, ioc := range iocs {
132148
ret = append(ret, ioc)

0 commit comments

Comments
 (0)