How do you retrieve cpu usage from Node in Kubernetes via API?

If you use Kubernetes v1.2, there is a new, cleaner metrics summary API. From the release note:

Kubelet exposes a new Alpha metrics API - /stats/summary in a user friendly format with reduced system overhead.

You can access the endpoint through <node-ip>:10255/stats/summary and detailed API objects is here.


So the way CPU usage metrics are usually collected in Kubernetes is using cAdvisor https://github.com/google/cadvisor which looks at the cgroups to get metircs, so mostly CPU and some memory metrics. cAdvisor then can put its data into a metrics DB like heapster, influxDB or prometheus. Kubernetes does not directly deal with metrics, so therefore does not expose it through the API, however you can use the metrics DB instead. Additionally you can use an additional container in your pod to collect metrics and place that into your metrics DB. Additionally, you can get resource quotas through the API, but not usage. This proposal may be of some interest for you as well https://github.com/kubernetes/kubernetes/blob/release-1.2/docs/proposals/metrics-plumbing.md.