Python 如何从metrics服务器获取Pod CPU和内存使用率?
我目前已在K8s群集中安装并运行metric server 利用kubernetes python库,我可以请求获取pod度量:Python 如何从metrics服务器获取Pod CPU和内存使用率?,python,kubernetes,kubernetes-helm,Python,Kubernetes,Kubernetes Helm,我目前已在K8s群集中安装并运行metric server 利用kubernetes python库,我可以请求获取pod度量: from kubernetes import client api_client = client.ApiClient() ret_metrics = api_client.call_api( '/apis/metrics.k8s.io/v1beta1/namespaces/' + 'default' + '/pods', 'GET',
from kubernetes import client
api_client = client.ApiClient()
ret_metrics = api_client.call_api(
'/apis/metrics.k8s.io/v1beta1/namespaces/' + 'default' + '/pods', 'GET',
auth_settings=['BearerToken'], response_type='json', _preload_content=False)
response = ret_metrics[0].data.decode('utf-8')
print('RESP', json.loads(response))
在响应中,每个pod的所有容器都将列出其cpu和内存使用情况:
'containers': [{'name': 'elasticsearch', 'usage': {'cpu': '14122272n', 'memory': '826100Ki'}}]}
现在我的问题是,如何获得pod本身而不是其容器的这些指标?如果可能的话,我不想总结每个容器的度量。使用metrics server有什么方法可以做到这一点吗 根据您可以查询的统计数据端点:
$ curl --insecure https://<node url>:10250/stats/summary
这些要求将起作用:
http://localhost:10255/stats/myapp/py588590/e0056f1a/py588590
你也可以找这个。我希望它能帮助你
{ "podRef":
{ "name": "py588590",
"namespace": "myapp",
"uid": "e0056f1a"
},
"startTime": "2019-10-16T03:57:47Z",
"containers":
[
{ "name": "py588590",
"startTime": "2019-10-16T03:57:50Z"
}
]
}
http://localhost:10255/stats/myapp/py588590/e0056f1a/py588590