Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions charts/spiderpool/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ spec:
image: {{ include "spiderpool.multus.image" . | quote }}
imagePullPolicy: IfNotPresent
command:
- /install_multus
- /install_multus
args:
- --type
- thin
- --type
- thin
securityContext:
privileged: true
volumeMounts:
- mountPath: /host/opt/cni/bin
mountPropagation: Bidirectional
name: cni-bin-path
- mountPath: /host/opt/cni/bin
mountPropagation: Bidirectional
name: cni-bin-path
{{- end }}
containers:
- name: {{ .Values.spiderpoolAgent.name | trunc 63 | trimSuffix "-" }}
Expand Down Expand Up @@ -235,7 +235,7 @@ spec:
volumeMounts:
{{- if .Values.spiderpoolAgent.prometheus.enabledRdmaMetric }}
- name: host-ns
mountPath: /var/run/netns
mountPath: /var/run
mountPropagation: Bidirectional
{{- end }}
- name: config-path
Expand All @@ -257,20 +257,20 @@ spec:
image: {{ include "spiderpool.spiderpoolAgent.image" . | quote }}
imagePullPolicy: {{ .Values.spiderpoolAgent.image.pullPolicy }}
command:
- "/home/entrypoint.sh"
- "/home/entrypoint.sh"
securityContext:
privileged: true
env:
- name: MULTUS_CLUSTER_NETWORK
valueFrom:
configMapKeyRef:
key: clusterNetwork
name: spiderpool-conf
- name: MULTUS_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: MULTUS_CLUSTER_NETWORK
valueFrom:
configMapKeyRef:
key: clusterNetwork
name: spiderpool-conf
- name: MULTUS_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
resources:
limits:
cpu: 100m
Expand Down Expand Up @@ -318,7 +318,7 @@ spec:
{{- if .Values.spiderpoolAgent.prometheus.enabledRdmaMetric }}
- name: host-ns
hostPath:
path: /var/run/netns
path: /var/run
{{- end }}
{{- if .Values.multus.multusCNI.install }}
- name: cni
Expand Down
82 changes: 78 additions & 4 deletions pkg/rdmametrics/ethtool/ethtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@

package ethtool

import "github.com/safchain/ethtool"
import (
"strconv"
"strings"

func Stats(netIfName string) (map[string]uint64, error) {
"github.com/safchain/ethtool"
"go.opentelemetry.io/otel/attribute"

"github.com/spidernet-io/spiderpool/pkg/rdmametrics/oteltype"
)

func Stats(netIfName string) ([]oteltype.Metrics, error) {
tool, err := ethtool.NewEthtool()
if err != nil {
return nil, err
Expand All @@ -15,13 +23,79 @@ func Stats(netIfName string) (map[string]uint64, error) {
if err != nil {
return nil, err
}

res := make([]oteltype.Metrics, 0)
for k, v := range stats {
if strings.Contains(k, "vport") {
res = append(res, oteltype.Metrics{Name: k, Value: int64(v)})
continue
}
if expectPriorityMetrics(k) {
name, priority, ok := extractNameWithPriority(k)
if ok {
res = append(res, oteltype.Metrics{
Name: name,
Value: int64(v),
Labels: []attribute.KeyValue{{
Key: "priority", Value: attribute.IntValue(priority),
}},
})
}
}
}

speed, err := tool.CmdGetMapped(netIfName)
if err != nil {
return nil, err
}

// speed unknown = 4294967295
if val, ok := speed["speed"]; ok && val != 4294967295 {
stats["vport_speed_mbps"] = val
res = append(res, oteltype.Metrics{
Name: "vport_speed_mbps",
Value: int64(val),
})
}
return res, nil
}

func expectPriorityMetrics(s string) bool {
if len(s) == 14 {
if (strings.HasPrefix(s, "rx_prio") || strings.HasPrefix(s, "tx_prio")) && strings.HasSuffix(s, "_pause") {
return true
}
}
if len(s) == 17 {
if (strings.HasPrefix(s, "rx_prio") || strings.HasPrefix(s, "tx_prio")) && strings.HasSuffix(s, "_discards") {
return true
}
}
return stats, nil
return false
}

func extractNameWithPriority(str string) (name string, priority int, ok bool) {
parts := strings.Split(str, "_")
if len(parts) != 3 {
return "", 0, false
}

name = parts[0] + "_" + parts[2]

rawPriority := parts[1]
if len(rawPriority) < 5 {
return "", 0, false
}

var err error

if strings.HasPrefix(rawPriority, "prio") {
priority, err = strconv.Atoi(strings.TrimPrefix(rawPriority, "prio"))
if err != nil {
return "", 0, false
}
} else {
return "", 0, false
}

return name, priority, true
}
Loading
Loading