File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments