如何从Metrics-Server获取Pod CPU和内存使用率? [英] How to get Pod CPU and Memory Usage from metrics-server?

查看:477
本文介绍了如何从Metrics-Server获取Pod CPU和内存使用率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在K8s集群中安装并运行了度量服务器.

I currently have metric server installed and running in my K8s cluster.

利用kubernetes python lib,我能够发出此请求以获取Pod指标:

Utilizing the the kubernetes python lib, I am able to make this request to get pod metrics:

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))

在响应中,将为每个容器列出所有容器及其CPU和内存使用情况:

In the response, for each pod all containers will be listed with their cpu and memory usage:

'containers': [{'name': 'elasticsearch', 'usage': {'cpu': '14122272n', 'memory': '826100Ki'}}]}

现在,我的问题是如何获取广告连播本身而不是其容器的这些指标?如果可能的话,我宁愿不必总结每个容器的指标.有什么办法可以使用metrics-server完成此操作吗?

Now my question is how do i get these metrics for the pod itself and not its containers? I'd rather not have to sum up the metrics from each container if possible. Is there any way to do this with metrics-server?

推荐答案

基于

Based on the official repository you can query kubelet stats endpoint:

$ curl --insecure https://<node url>:10250/stats/summary

,它将返回完整Pod的统计信息.如果要查看容器/容器本身的指标,请输入:

which will return stats of full pods. If you want to see metrics for pod/container itself, type:

$ curl --insecure https://<node url>:10250/{namespace}/{podName}/{uid}/{containerName}

让我们来看一个例子:

{ "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

您也可以查找此文章.希望对您有帮助.

You can also look for this article. I hope it will helps you.

这篇关于如何从Metrics-Server获取Pod CPU和内存使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆