Skip to content

Commit 3df0d4f

Browse files
add k8s.pod.cpu.node.utilization metric and tests (#31)
Signed-off-by: Tetiana Kravchenko <[email protected]>
1 parent 030b953 commit 3df0d4f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

remappers/kubernetesmetrics/k8smetrics_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
7777
input: []internal.TestMetric{
7878
{Type: Gauge, Name: "k8s.pod.cpu_limit_utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.26), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
7979
{Type: Gauge, Name: "k8s.pod.memory_limit_utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.18), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
80+
{Type: Gauge, Name: "k8s.pod.cpu.node.utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.12), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
8081
{Type: Sum, Name: "k8s.pod.network.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024)), Attrs: map[string]any{"device": DEVICE, "direction": "receive"}}},
8182
{Type: Sum, Name: "k8s.pod.network.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: map[string]any{"device": DEVICE, "direction": "transmit"}}},
8283
},
8384
expected: []internal.TestMetric{
8485
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.limit.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.26), Attrs: outAttr("kubeletstatsreceiver")}},
85-
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.node.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("kubeletstatsreceiver")}},
86+
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.node.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.12), Attrs: outAttr("kubeletstatsreceiver")}},
8687
{Type: Gauge, Name: "kubernetes.pod.memory.usage.node.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("kubeletstatsreceiver")}},
8788
{Type: Gauge, Name: "kubernetes.pod.memory.usage.limit.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.18), Attrs: outAttr("kubeletstatsreceiver")}},
8889
{Type: Sum, Name: "kubernetes.pod.network.tx.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: outAttr("kubeletstatsreceiver")}},
@@ -115,6 +116,7 @@ func BenchmarkRemap(b *testing.B) {
115116
in := map[string][]internal.TestMetric{
116117
"kubeletstats": []internal.TestMetric{
117118
{Type: Gauge, Name: "k8s.pod.cpu_limit_utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.26), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
119+
{Type: Gauge, Name: "k8s.pod.cpu.node.utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.12), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
118120
{Type: Gauge, Name: "k8s.pod.memory_limit_utilization", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.18), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
119121
{Type: Sum, Name: "k8s.pod.network.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024)), Attrs: map[string]any{"device": DEVICE, "direction": "receive"}}},
120122
{Type: Sum, Name: "k8s.pod.network.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: map[string]any{"device": DEVICE, "direction": "transmit"}}},

remappers/kubernetesmetrics/kubelet.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ func addKubeletMetrics(
3838
//pod
3939
for i := 0; i < src.Len(); i++ {
4040
metric := src.At(i)
41-
// kubernetes.pod.cpu.usage.node.pct and kubernetes.pod.memory.usage.node.pct still needs to be implemented
41+
// kubernetes.pod.memory.usage.node.pct still needs to be implemented
4242
if metric.Name() == "k8s.pod.cpu_limit_utilization" {
4343
dp := metric.Gauge().DataPoints().At(0)
4444
if timestamp == 0 {
4545
timestamp = dp.Timestamp()
4646
}
4747
cpu_limit_utilization = dp.DoubleValue()
48+
} else if metric.Name() == "k8s.pod.cpu.node.utilization" {
49+
dp := metric.Gauge().DataPoints().At(0)
50+
if timestamp == 0 {
51+
timestamp = dp.Timestamp()
52+
}
53+
pod_cpu_usage_node = dp.DoubleValue()
4854
} else if metric.Name() == "k8s.pod.memory_limit_utilization" {
4955
dp := metric.Gauge().DataPoints().At(0)
5056
if timestamp == 0 {

0 commit comments

Comments
 (0)