Skip to content

Commit 976e418

Browse files
committed
simplfy example
1 parent 9b4ffe2 commit 976e418

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

examples/top_pods.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,31 @@ const metricsClient = new k8s.Metrics(kc);
99
k8s.topPods(k8sApi, metricsClient, "kube-system")
1010
.then((pods) => {
1111

12-
const podsColumns = pods.reduce((accum, next) => {
13-
accum.push({
14-
"POD": next.Pod.metadata.name,
15-
"CPU(cores)": next.CPU.CurrentUsage,
16-
"MEMORY(bytes)": next.Memory.CurrentUsage,
17-
});
18-
return accum;
19-
}, []);
12+
const podsColumns = pods.map((pod) => {
13+
return {
14+
"POD": pod.Pod.metadata.name,
15+
"CPU(cores)": pod.CPU.CurrentUsage,
16+
"MEMORY(bytes)": pod.Memory.CurrentUsage,
17+
}
18+
});
2019
console.log("TOP PODS")
2120
console.table(podsColumns)
2221
});
2322

2423
k8s.topPods(k8sApi, metricsClient, "kube-system")
2524
.then((pods) => {
2625

27-
const podsColumns = pods.reduce((accum, next) => {
28-
29-
next.Containers.forEach(containerUsage => {
30-
accum.push({
31-
"POD": next.Pod.metadata.name,
26+
const podsAndContainersColumns = pods.flatMap((pod) => {
27+
return pod.Containers.map(containerUsage => {
28+
return {
29+
"POD": pod.Pod.metadata.name,
3230
"NAME": containerUsage.Container,
33-
"CPU(cores)": next.CPU.CurrentUsage,
34-
"MEMORY(bytes)": next.Memory.CurrentUsage,
35-
});
31+
"CPU(cores)": containerUsage.CPUUsage.CurrentUsage,
32+
"MEMORY(bytes)": containerUsage.MemoryUsage.CurrentUsage,
33+
};
3634
})
37-
return accum;
38-
}, []);
35+
});
3936

4037
console.log("TOP CONTAINERS")
41-
console.table(podsColumns)
38+
console.table(podsAndContainersColumns)
4239
});

0 commit comments

Comments
 (0)