1+ // in a real program use require('@kubernetes/client-node')
12const k8s = require ( '../dist/index' ) ;
23
34const kc = new k8s . KubeConfig ( ) ;
@@ -6,34 +7,30 @@ kc.loadFromDefault();
67const k8sApi = kc . makeApiClient ( k8s . CoreV1Api ) ;
78const metricsClient = new k8s . Metrics ( kc ) ;
89
9- k8s . topPods ( k8sApi , metricsClient , "kube-system" )
10- . then ( ( pods ) => {
11-
10+ k8s . topPods ( k8sApi , metricsClient , 'kube-system' ) . then ( ( pods ) => {
1211 const podsColumns = pods . map ( ( pod ) => {
1312 return {
14- " POD" : pod . Pod . metadata . name ,
15- " CPU(cores)" : pod . CPU . CurrentUsage ,
16- " MEMORY(bytes)" : pod . Memory . CurrentUsage ,
17- }
13+ POD : pod . Pod . metadata ? .name ,
14+ ' CPU(cores)' : pod . CPU . CurrentUsage ,
15+ ' MEMORY(bytes)' : pod . Memory . CurrentUsage ,
16+ } ;
1817 } ) ;
19- console . log ( " TOP PODS" )
20- console . table ( podsColumns )
18+ console . log ( ' TOP PODS' ) ;
19+ console . table ( podsColumns ) ;
2120} ) ;
2221
23- k8s . topPods ( k8sApi , metricsClient , "kube-system" )
24- . then ( ( pods ) => {
25-
22+ k8s . topPods ( k8sApi , metricsClient , 'kube-system' ) . then ( ( pods ) => {
2623 const podsAndContainersColumns = pods . flatMap ( ( pod ) => {
27- return pod . Containers . map ( containerUsage => {
24+ return pod . Containers . map ( ( containerUsage ) => {
2825 return {
29- " POD" : pod . Pod . metadata . name ,
30- " NAME" : containerUsage . Container ,
31- " CPU(cores)" : containerUsage . CPUUsage . CurrentUsage ,
32- " MEMORY(bytes)" : containerUsage . MemoryUsage . CurrentUsage ,
26+ POD : pod . Pod . metadata ? .name ,
27+ NAME : containerUsage . Container ,
28+ ' CPU(cores)' : containerUsage . CPUUsage . CurrentUsage ,
29+ ' MEMORY(bytes)' : containerUsage . MemoryUsage . CurrentUsage ,
3330 } ;
34- } )
31+ } ) ;
3532 } ) ;
3633
37- console . log ( " TOP CONTAINERS" )
38- console . table ( podsAndContainersColumns )
39- } ) ;
34+ console . log ( ' TOP CONTAINERS' ) ;
35+ console . table ( podsAndContainersColumns ) ;
36+ } ) ;
0 commit comments