How to get following metrics from k8s: Total and free cpus/mem in the cluster?


We use a bespoke cluster autoscaler to scale our mesos clusters up and down. We do it based on total and available(free) cpus/mem in the cluster. Does k8s expose this? I read the docs, but could find any information pertaining to it.



Kubectl describe node shows the cpu request and limit, same for mem, for each node.

Does that help? :slight_smile:


Sounds like you would like to know metrics about the cluster itself.
The metrics-server will make those available for consumption with a tool of your choice.


@rata, @RiRa12621, thanks for your reply!

I am looking to fetch these metrics in a script, so metrics-server seems like a better option.

My understanding is that metrics-server uses ‘stats/summary’ API of kubelet to get metrics. Looks like Kubelet API provides metrics pertaining to the actual cpu usage. I am looking for the cpu/mem reservation information. Am I missing something?


We use prometheus metrics to get the similar view, cadvisor metrics combined with provides plenty of the information.

container_spec_cpu_shares from kubelet cadvisor can be used to get how much allocated and kube_node_status_allocatable_cpu_cores from kube-state-metrics provides how much available in the cluster.


@vnandha Thanks for sharing the information. has all the metrics I was looking for. I feel these metrics are really critical from cluster administrator’s point of view and should be a little bit easier to discover.


@sagarp We also presented our work at Kubecon Copenhagen about complete monitoring suite and dashboards we build that are really crucial for day to day operation. You can check out the video and some links to dashboard source
Federated Prometheus Monitoring at Scale - Nandhakumar Venkatachalam & LungChih Tung ( )