<p>Is there a Java API to retrieve the CPU and Memory usage of the pod? I am not looking for a complete monitoring solution like using Grafana or Prometheus or not using the kubectl top pod, but wanted to retrieve the current usage using Java API. Any example or reference documentation on how to do will be of great help.</p>

<p>Client libraries</p>

<p><a href="https://kubernetes.io/docs/reference/using-api/client-libraries/" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/using-api/client-libraries/</a></p>

<p>Examples - <a href="https://github.com/kubernetes-client/java#installation" rel="nofollow noreferrer">https://github.com/kubernetes-client/java#installation</a></p>

<p>Similar questions:</p>

<p><a href="https://stackoverflow.com/questions/44352621/how-to-get-max-usage-of-mem-and-cpu-usage-of-pod-on-kubernetes">how to get max usage of mem and cpu usage of pod on kubernetes</a></p>

<p><a href="https://stackoverflow.com/questions/60144569/kubernetes-pod-cpu-usage-in-from-metric-server">kubernetes Pod CPU usage in % from metric server</a></p>

<p>Thanks.</p>

<p>You can install the <a href="https://github.com/kubernetes-sigs/metrics-server" rel="nofollow noreferrer">Metrics Server</a> and then fetch the resource usage of Pods with direct HTTP requests to the <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/resource-metrics-api.md#endpoints" rel="nofollow noreferrer">Resource Metrics API</a> through the API server:</p>

<pre><code>GET /apis/metrics/v1alpha1/namespaces/{namespace}/pods/{pod}
</code></pre>

<p>The Resource Metrics API does not seem to be included in the official <a href="https://github.com/kubernetes-client/java/" rel="nofollow noreferrer">Java client library</a>. So, you probably have to make the API requests manually.</p>
