Skip to content

Instantly share code, notes, and snippets.

@UlricQin
Last active April 26, 2024 03:23
Show Gist options
  • Save UlricQin/9eeca5d520e03ffa10832b27bf8f8f42 to your computer and use it in GitHub Desktop.
Save UlricQin/9eeca5d520e03ffa10832b27bf8f8f42 to your computer and use it in GitHub Desktop.

cpu 使用率

container!="POD" 是过滤掉 pause 容器。这个 promql 比较难以理解,分子是:每秒内,容器用了多少CPU时间,分母是:每秒内,被限制使用多少CPU时间

sum(
  irate(container_cpu_usage_seconds_total[3m])
) by (pod,id,namespace,container,ident,image)
/
sum(
  container_spec_cpu_quota/container_spec_cpu_period
) by (pod,id,namespace,container,ident,image)

mem 使用率

内存使用量除以内存限制量,就是使用率,但是后面跟了 and container_spec_memory_limit_bytes != 0 是因为有些容器没有配置 limit 的内存大小

container_memory_usage_bytes/container_spec_memory_limit_bytes
and
container_spec_memory_limit_bytes != 0

实际上,更应该用的是 container_memory_working_set_bytes 指标来计算内存使用率。详细参考 这篇文章

net 入流量

这个比较简单,irate 之后乘以 8 是换算成 bit 作为单位

irate(container_network_receive_bytes_total[1m]) * 8

net 出流量

这个比较简单,irate 之后乘以 8 是换算成 bit 作为单位

irate(container_network_transmit_bytes_total[1m]) * 8

CPU被限制的时间比例

对于高算力需求的进程,如果分配的CPU不够用,这个指标会飙高,说明要升配了

increase(container_cpu_cfs_throttled_periods_total[1m])
/
increase(container_cpu_cfs_periods_total[1m]) * 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment