@@ -9,34 +9,31 @@ const metricsClient = new k8s.Metrics(kc);
9
9
k8s . topPods ( k8sApi , metricsClient , "kube-system" )
10
10
. then ( ( pods ) => {
11
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
- } , [ ] ) ;
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
+ } ) ;
20
19
console . log ( "TOP PODS" )
21
20
console . table ( podsColumns )
22
21
} ) ;
23
22
24
23
k8s . topPods ( k8sApi , metricsClient , "kube-system" )
25
24
. then ( ( pods ) => {
26
25
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 ,
32
30
"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
+ } ;
36
34
} )
37
- return accum ;
38
- } , [ ] ) ;
35
+ } ) ;
39
36
40
37
console . log ( "TOP CONTAINERS" )
41
- console . table ( podsColumns )
38
+ console . table ( podsAndContainersColumns )
42
39
} ) ;
0 commit comments