Skip to content

Commit aef7c1c

Browse files
committed
Cherry pick rdma metrics from main
Signed-off-by: lou-lan <[email protected]>
1 parent 86681a3 commit aef7c1c

File tree

7 files changed

+782
-686
lines changed

7 files changed

+782
-686
lines changed

charts/spiderpool/templates/daemonset.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ spec:
235235
volumeMounts:
236236
{{- if .Values.spiderpoolAgent.prometheus.enabledRdmaMetric }}
237237
- name: host-ns
238-
mountPath: /var/run/netns
238+
mountPath: /var/run
239239
mountPropagation: Bidirectional
240240
{{- end }}
241241
- name: config-path
@@ -318,9 +318,8 @@ spec:
318318
{{- if .Values.spiderpoolAgent.prometheus.enabledRdmaMetric }}
319319
- name: host-ns
320320
hostPath:
321-
path: /var/run/netns
322-
{{- end }}
323-
{{- if .Values.multus.multusCNI.install }}
321+
path: "/var/run"
322+
{{- if .Values.multus.multusCNI.install }}
324323
- name: cni
325324
hostPath:
326325
path: /etc/cni/net.d

pkg/rdmametrics/ethtool/ethtool.go

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33

44
package ethtool
55

6-
import "github.com/safchain/ethtool"
6+
import (
7+
"strconv"
8+
"strings"
79

8-
func Stats(netIfName string) (map[string]uint64, error) {
10+
"github.com/safchain/ethtool"
11+
"go.opentelemetry.io/otel/attribute"
12+
13+
"github.com/spidernet-io/spiderpool/pkg/rdmametrics/oteltype"
14+
)
15+
16+
func Stats(netIfName string) ([]oteltype.Metrics, error) {
917
tool, err := ethtool.NewEthtool()
1018
if err != nil {
1119
return nil, err
@@ -15,13 +23,79 @@ func Stats(netIfName string) (map[string]uint64, error) {
1523
if err != nil {
1624
return nil, err
1725
}
26+
27+
res := make([]oteltype.Metrics, 0)
28+
for k, v := range stats {
29+
if strings.Contains(k, "vport") {
30+
res = append(res, oteltype.Metrics{Name: k, Value: int64(v)})
31+
continue
32+
}
33+
if expectPriorityMetrics(k) {
34+
name, priority, ok := extractNameWithPriority(k)
35+
if ok {
36+
res = append(res, oteltype.Metrics{
37+
Name: name,
38+
Value: int64(v),
39+
Labels: []attribute.KeyValue{{
40+
Key: "priority", Value: attribute.IntValue(priority),
41+
}},
42+
})
43+
}
44+
}
45+
}
46+
1847
speed, err := tool.CmdGetMapped(netIfName)
1948
if err != nil {
2049
return nil, err
2150
}
51+
2252
// speed unknown = 4294967295
2353
if val, ok := speed["speed"]; ok && val != 4294967295 {
24-
stats["vport_speed_mbps"] = val
54+
res = append(res, oteltype.Metrics{
55+
Name: "vport_speed_mbps",
56+
Value: int64(val),
57+
})
58+
}
59+
return res, nil
60+
}
61+
62+
func expectPriorityMetrics(s string) bool {
63+
if len(s) == 14 {
64+
if (strings.HasPrefix(s, "rx_prio") || strings.HasPrefix(s, "tx_prio")) && strings.HasSuffix(s, "_pause") {
65+
return true
66+
}
67+
}
68+
if len(s) == 17 {
69+
if (strings.HasPrefix(s, "rx_prio") || strings.HasPrefix(s, "tx_prio")) && strings.HasSuffix(s, "_discards") {
70+
return true
71+
}
2572
}
26-
return stats, nil
73+
return false
74+
}
75+
76+
func extractNameWithPriority(str string) (name string, priority int, ok bool) {
77+
parts := strings.Split(str, "_")
78+
if len(parts) != 3 {
79+
return "", 0, false
80+
}
81+
82+
name = parts[0] + "_" + parts[2]
83+
84+
rawPriority := parts[1]
85+
if len(rawPriority) < 5 {
86+
return "", 0, false
87+
}
88+
89+
var err error
90+
91+
if strings.HasPrefix(rawPriority, "prio") {
92+
priority, err = strconv.Atoi(strings.TrimPrefix(rawPriority, "prio"))
93+
if err != nil {
94+
return "", 0, false
95+
}
96+
} else {
97+
return "", 0, false
98+
}
99+
100+
return name, priority, true
27101
}

0 commit comments

Comments
 (0)