How to measure the CPU utilization of Each container in Mesos?

爱⌒轻易说出口 提交于 2019-12-06 03:51:04
janisz

In Mesos WebUI you can see how much CPU is used by your executor

Here is the code that collects statistics from /monitor/statistics endpoint and calculate CPU usage.

You are interested in cpus_total_usage so the following method should works for you

Let's assume a and b are snapshot of statistics at some point in time. To calculate cpus_total_usage, we need calculate the time executor spent in the system and user space and divide it by the time elapsed between a and b.

cpus_total_usage = (
                    (b.cpus_system_time_secs - a.cpus_system_time_secs) +
                    (b.cpus_user_time_secs - a.cpus_user_time_secs)) / 
                    (b.timestamp - a.timestamp)
                   )
cpu_percent      = cpus_total_usage / cpu_limit * 100%

Depending on how much work you want to invest yourself, you can either use the Marathon Event Bus and more generally the Marathon HTTP API (for example this endpoint) along with low-level tools like cAdvisor or cinf to do the maths yourself. If you don't want to code stuff yourself, I suggest you use Sysdig, Datadog or Prometheus to do the heavy lifting for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!