Skip to content

Commit dd377c7

Browse files
authored
Fix softnet CPU Index (prometheus#517)
When parsing older kernel versoins, we assume the CPU is indexed based on the parsed line, rather than an explicit index column. Signed-off-by: SuperQ <[email protected]>
1 parent 58149ca commit dd377c7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

net_softnet.go

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
7676
s := bufio.NewScanner(r)
7777

7878
var stats []SoftnetStat
79+
cpuIndex := 0
7980
for s.Scan() {
8081
columns := strings.Fields(s.Text())
8182
width := len(columns)
@@ -127,9 +128,13 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
127128

128129
softnetStat.SoftnetBacklogLen = us[0]
129130
softnetStat.Index = us[1]
131+
} else {
132+
// For older kernels, create the Index based on the scan line number.
133+
softnetStat.Index = uint32(cpuIndex)
130134
}
131135
softnetStat.Width = width
132136
stats = append(stats, softnetStat)
137+
cpuIndex++
133138
}
134139

135140
return stats, nil

net_softnet_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ func TestNetSoftnet(t *testing.T) {
5555
CPUCollision: 0x00000004,
5656
ReceivedRps: 0x00000003,
5757
FlowLimitCount: 0x00000002,
58+
Index: 0x00000002,
5859
Width: 11,
5960
},
6061
{
6162
Processed: 0x01663fb2,
6263
Dropped: 0x00000000,
6364
TimeSqueezed: 0x0109a4,
6465
CPUCollision: 0x00020e76,
66+
Index: 0x00000003,
6567
Width: 9,
6668
},
6769
{
@@ -70,6 +72,7 @@ func TestNetSoftnet(t *testing.T) {
7072
TimeSqueezed: 0x00000011,
7173
CPUCollision: 0x00000020,
7274
ReceivedRps: 0x00000010,
75+
Index: 0x00000004,
7376
Width: 10,
7477
},
7578
}

0 commit comments

Comments
 (0)