Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: How to get disk / cpu metrics of a node

Tags:

kubernetes

Without using Heapster is there any way to collect like CPU or Disk metrics about a node within a Kubernetes cluster?

How does Heapster even collect those metrics in the first place?

like image 972
adrian Avatar asked Feb 04 '16 21:02

adrian


2 Answers

Kubernetes monitoring is detailed in the documentation here, but that mostly covers tools using heapster.

Node-specific information is exposed through the cAdvisor UI which can be accessed on port 4194 (see the commands below to access this through the proxy API).

Heapster queries the kubelet for stats served at <kubelet address>:10255/stats/ (other endpoints can be found in the code here).

Try this:

$ kubectl proxy &
Starting to serve on 127.0.0.1:8001
$ NODE=$(kubectl get nodes -o=jsonpath="{.items[0].metadata.name}")
$ curl -X "POST" -d '{"containerName":"/","subcontainers":true,"num_stats":1}' localhost:8001/api/v1/proxy/nodes/${NODE}:10255/stats/container
...

Note that these endpoints are not documented as they are intended for internal use (and debugging), and may change in the future (we eventually want to offer a more stable versioned endpoint).

Update:

As of Kubernetes version 1.2, the Kubelet exports a "summary" API that aggregates stats from all Pods:

$ kubectl proxy &
Starting to serve on 127.0.0.1:8001
$ NODE=$(kubectl get nodes -o=jsonpath="{.items[0].metadata.name}")
$ curl localhost:8001/api/v1/proxy/nodes/${NODE}:10255/stats/summary
...
like image 85
Tim Allclair Avatar answered Nov 16 '22 01:11

Tim Allclair


I would recommend using heapster to collect metrics. It's pretty straight forward. However, in order to access those metrics, you need to add "type: NodePort" in hepaster.yml file. I modified the original heapster files and you can found them here. See my readme file how to access metrics. More metrics are available here.

Metrics can be accessed via a web browser by accessing http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate. The Same result can be seen by executing following command.

$ curl -L http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate   
like image 37
Abu Shoeb Avatar answered Nov 16 '22 03:11

Abu Shoeb