简体   繁体   中英

Getting metrics via metrics-server [kubernetes]

I want to get the cpu and memory usage of a particular pod inside my python program. I tried heapster, but since it is in deprecating state I was forced to use metrics-server. metrics-server returns cpu and memory usage of that command executed time. Heapster was returning list of metrics in each minute from the pod created time to command executed time and also within a start time and end time. How will we get the same using metrics-server?like memory and cpu usage within a start and end time?

Is there any flags to get that?

I tried this - using metrics-server

kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespace/<namespace>/pods/<podname>

The above command returns the cpu and memory usage of a specified pod at that time.

Sample output :slight_smile:

{“kind”:“PodMetrics”,“apiVersion”:“metrics.k8s.io/v1beta1”,

“metadata”:{“name”:“podname”,“namespace”:“default”,“selfLink”:"/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/podname",

“creationTimestamp”:“2019-06-26T03:41:25Z”},“timestamp”:“2019-06-26T03:41:00Z”,“window”:“1m0s”,

“containers”:[{“name”:“cassandra”,“usage”:{“cpu”:“4m”,“memory”:“816388Ki”}}]}

I tried the same with curl command also.

curl http://127.0.0.1:8001/apis/metrics.k8s.io/v1beta1/namespace/<namespace-name>/pods/<pod-name> -k

This also returns the same..

I expect the metrics within a start time and end time. But this gives metrics usage at the current time.

It's not possible via metrics-server, you can only get currrently used resources ( see docs ).

For actual monitoring check out Prometheus or similar services .

我在 python 中使用 kuberenetes 客户端包在 pod 内执行 kubectl 命令并使用“threding”,收集一段时间内的最大指标。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM