alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.41k stars 8.03k forks source link

Get system metrics of container | k8s pod里SystemStatusListener获取到的是物理机的load不是pod的load #2260

Open supercocoa opened 3 years ago

supercocoa commented 3 years ago

Issue Description

k8s pod里SystemStatusListener获取到的是物理机的load不是pod的load

Describe what you expected to happen

可以获取到pod或容器里的load

Tell us your environment

k8s

sczyh30 commented 3 years ago

这个确实是个问题,社区可以一起来看一下获取容器 load 的比较好的方式。

brotherlu-xcq commented 3 years ago

The same issue entranced in https://github.com/micrometer-metrics/micrometer/issues/1534.

sczyh30 commented 3 years ago

Also refer https://github.com/alibaba/sentinel-golang/pull/415

HobbyBear commented 3 years ago

The same issue entranced in micrometer-metrics/micrometer#1534.

maybe you can refer this https://juejin.cn/post/6986598285406371871/ ,it is my ideas about solving this.

haoyann commented 2 years ago

容器里获取 CPU 可以参考以下方法:

  1. 读取 /sys/fs/cgroup/cpu/cpuacct.usage 文件获取容器总的 CPU 耗时,cpuDelta 为两次读取的差值;
  2. 读取 /proc/stat 文件获取系统总的 CPU 耗时,systemDelta 为两次读取的差值;
  3. 读取 /sys/fs/cgroup/cpuacct/cpuacct.usage_percpu 文件获取系统分给容器的CPU总核数,percpuUsage 为该值;
  4. 当前CPU使用率为: cpuPercent = (cpuDelta / systemDelta) * percpuUsage (cpuDelta、systemDelta 需要进行单位换算)

参考:https://stackoverflow.com/questions/35692667/in-docker-cpu-usage-calculation-what-are-totalusage-systemusage-percpuusage-a

lbbniu commented 4 months ago

怎么没有了后续的支持更新呢,是项目不维护了吗?