How do you get CPU usage from Node in Kubernetes via API?

I want to calculate and show node specific processor utilization as a percentage in my own web application using the Kubernetes API.

I need the same information as the Kube UI and Cadvisor mappings, but I want to use the Kubernetes API.

I found some cpu metrics in the node -ip: 10255 / stats section, which contains the timestamp, CPU usage: total, user and system in large weird numbers that I don't understand. In addition, the CPU Limit is reported as 1024.

How does the Kube user interface calculate processor utilization and is it possible to do this through the API?

+5
source share
2 answers

If you use Kubernetes v1.2, a new, cleaner Totals API appears. 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 via <node-ip>:10255/stats/summary and detailed API objects here .

+3
source

Thus, as a rule, CPU utilization metrics are usually collected in Kubernetes using the cAdvisor https://github.com/google/cadvisor , which looks at groups to get metircs, which is why the CPU and some memory metrics are mainly. CAdvisor can then put its data into a metric database such as a bush, infuxDB or prometheus. Kubernetes is not directly related to metrics, so it does not provide it through the API, but you can use a metric database instead. In addition, you can use an additional container in your package to collect indicators and place it in your indicators database. In addition, you can get resource quotas through the API, but not use it. This proposal may interest you, but https://github.com/kubernetes/kubernetes/blob/release-1.2/docs/proposals/metrics-plumbing.md .

+2
source

Source: https://habr.com/ru/post/1246179/


All Articles