Kubernetes:如何获取节点的磁盘/cpu 指标
Kubernetes: How to get disk / cpu metrics of a node
在不使用 Heapster 的情况下,是否有任何方法可以收集 CPU 或有关 Kubernetes 集群中节点的磁盘指标?
Heapster 最初是如何收集这些指标的?
Kubernetes 监控在文档 here 中有详细说明,但主要涵盖使用 heapster 的工具。
节点特定信息通过 cAdvisor UI 公开,可以在端口 4194 上访问(请参阅下面的命令以通过代理 API 访问此信息)。
Heapster 向 kubelet 查询在 <kubelet address>:10255/stats/
提供的统计信息(其他端点可以在代码 here 中找到)。
试试这个:
$ 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
...
请注意,这些端点未记录在案,因为它们仅供内部使用(和调试),并且将来可能会发生变化(我们最终希望提供更稳定的版本化端点)。
更新:
从 Kubernetes 1.2 版开始,Kubelet 导出一个 "summary" API 聚合来自所有 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
...
我建议使用 heapster 来收集指标。这很简单。但是,为了访问这些指标,您需要在 hepaster.yml 文件中添加 "type: NodePort"。我修改了原始的 heapster 文件,你可以找到它们 here. See my readme file how to access metrics. More metrics are available here。
可以通过 Web 浏览器访问 http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate 来访问指标。执行以下命令可以看到相同的结果。
$ curl -L http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate
在不使用 Heapster 的情况下,是否有任何方法可以收集 CPU 或有关 Kubernetes 集群中节点的磁盘指标?
Heapster 最初是如何收集这些指标的?
Kubernetes 监控在文档 here 中有详细说明,但主要涵盖使用 heapster 的工具。
节点特定信息通过 cAdvisor UI 公开,可以在端口 4194 上访问(请参阅下面的命令以通过代理 API 访问此信息)。
Heapster 向 kubelet 查询在 <kubelet address>:10255/stats/
提供的统计信息(其他端点可以在代码 here 中找到)。
试试这个:
$ 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
...
请注意,这些端点未记录在案,因为它们仅供内部使用(和调试),并且将来可能会发生变化(我们最终希望提供更稳定的版本化端点)。
更新:
从 Kubernetes 1.2 版开始,Kubelet 导出一个 "summary" API 聚合来自所有 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
...
我建议使用 heapster 来收集指标。这很简单。但是,为了访问这些指标,您需要在 hepaster.yml 文件中添加 "type: NodePort"。我修改了原始的 heapster 文件,你可以找到它们 here. See my readme file how to access metrics. More metrics are available here。
可以通过 Web 浏览器访问 http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate 来访问指标。执行以下命令可以看到相同的结果。
$ curl -L http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/cpu/usage_rate