Skip to content
Advertisement

how to get the Node CPU% and MEMORY% value using java io.fabric8 kubernetes-client library

kubectl top nodes
NAME                      CPU(cores)   CPU%  MEMORY(bytes)  MEMORY%

gsdjsgfhdsgfz-12345665-jisj000000 934m       24%     10439Mi       82%
gsdjsgfhdsgfz-12345665-jisj000001 717m       18%     9132Mi         72%
gsdjsgfhdsgfz-12345665-jisj000002 1099m         28%     7614Mi       60%

how to get the CPU% and MEMORY% value using java io.fabric8 kubernetes-client library.

JavaScript

}

getting output is:-
node name
cpu:-1094942089n
memory:-7830672Ki

how will take the percentage values?

Advertisement

Answer

I had to implement this same feature recently, unfortunately I didn’t find a way to get the percentages just by using the top() API alone, I had to perform two calls, one to nodes() in order to retrieve total capacity and another one to top() to retrieve used capacity. Then it was just a matter of calculating percentage.

A snippet of the working code:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement