Skip to content

Commit 9b4ffe2

Browse files
committed
add example
1 parent 4ac6d39 commit 9b4ffe2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/top_pods.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const k8s = require('../dist/index');
2+
3+
const kc = new k8s.KubeConfig();
4+
kc.loadFromDefault();
5+
6+
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
7+
const metricsClient = new k8s.Metrics(kc);
8+
9+
k8s.topPods(k8sApi, metricsClient, "kube-system")
10+
.then((pods) => {
11+
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+
}, []);
20+
console.log("TOP PODS")
21+
console.table(podsColumns)
22+
});
23+
24+
k8s.topPods(k8sApi, metricsClient, "kube-system")
25+
.then((pods) => {
26+
27+
const podsColumns = pods.reduce((accum, next) => {
28+
29+
next.Containers.forEach(containerUsage => {
30+
accum.push({
31+
"POD": next.Pod.metadata.name,
32+
"NAME": containerUsage.Container,
33+
"CPU(cores)": next.CPU.CurrentUsage,
34+
"MEMORY(bytes)": next.Memory.CurrentUsage,
35+
});
36+
})
37+
return accum;
38+
}, []);
39+
40+
console.log("TOP CONTAINERS")
41+
console.table(podsColumns)
42+
});

0 commit comments

Comments
 (0)