简体   繁体   English

实时监控k8s容器中的CPU使用率/ CPU限制

[英]Realtime monitoring of CPU usage/CPU limit in k8s container

I am trying to measure CPU usage of a container in Kubernetes, represented as a ratio between actual usage and usage limit in a short time window. 我正在尝试在Kubernetes中测量容器的CPU使用率,表示为短时间窗口中实际使用率与使用率限制之间的比率。 This should be ideally close to real-time (up to 5s delay). 理想情况下,这应该接近实时(最多5s延迟)。

I have full control of the container code and I can also extend the pod with a sidecar container to do reporting for me. 我可以完全控制容器代码,也可以使用sidecar容器扩展容器,以便为我做报告。

I have looked at Prometheus deployed using Prometheus operator, but I am seeing the data landing with large delays or even not showing up at all for some pods. 我已经看过使用Prometheus运算符部署的Prometheus,但是我看到数据着陆时有很大的延迟,甚至对于某些吊舱甚至根本没有显示出来。

I was hoping somebody could shed some light on how to implement any of those: 我希望有人可以阐明如何实施其中任何一个:

  1. sidecar container that can query cpu usage/cpu limit and send the data to another service (I am worried that this is impossible, because containers run in isolated file systems). 可以查询cpu使用率/ cpu限制并将数据发送到另一服务的sidecar容器(我担心这是不可能的,因为容器在隔离的文件系统中运行)。
  2. another process within main container, that can do the reporting. 主容器中的另一个过程,可以执行报告。 Maybe dividing $(cat /sys/fs/cgroup/cpu/cpuacct.usage) / $(/sys/fs/cgroup/cpu/cpu.cfs_quota_us) would do the trick? 也许用$(cat /sys/fs/cgroup/cpu/cpuacct.usage)/ $(/ sys / fs / cgroup / cpu / cpu.cfs_quota_us)来解决问题?
  3. use some existing software tool/service to achieve this. 使用一些现有的软件工具/服务来实现此目的。 Any recommendation would be appreciated. 任何建议,将不胜感激。

Thank you very much! 非常感谢你!

Deploy a sidecar container along with the container that you want to monitor. 与要监视的容器一起部署sidecar容器。 The sidecar container should monitor the cpu of the main container and push the status to prometheus or some other monitoring service. 边车容器应监视主容器的cpu,并将其状态推送给Prometheus或其他监视服务。 With alerting you can set thresholds and if the cpu is over the threshold then prometheus would trigger an alert action through alert manager service 通过警报,您可以设置阈值,如果cpu超过阈值,则prometheus将通过警报管理器服务触发警报操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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