成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何正確計算 Kubernetes 容器 CPU 使用率

開源 Linux
使用 Prometheus 配置 kubernetes 環境中 Container 的 CPU 使用率時,會經常遇到 CPU 使用超出 100%問題,本文講解如何正確計算 Kubernetes 容器 CPU 使用率。

圖片

參數解釋

使用 Prometheus 配置 kubernetes 環境中 Container 的 CPU 使用率時,會經常遇到 CPU 使用超出 100%,下面就來解釋一下:

1.container_spec_cpu_period
當對容器進行 CPU 限制時,CFS 調度的時間窗口,又稱容器 CPU 的時鐘周期通常是 100,000 微秒

2.container_spec_cpu_quota
是指容器的使用 CPU 時間周期總量,如果 quota 設置的是 700,000,就代表該容器可用的 CPU 時間是 7*100,000 微秒,通常對應 kubernetes 的 resource.cpu.limits 的值

3.container_spec_cpu_share
是指 container 使用分配主機 CPU 相對值,比如 share 設置的是 500m,代表窗口啟動時向主機節點申請 0.5 個 CPU,也就是 50,000 微秒,通常對應 kubernetes 的 resource.cpu.requests 的值

4.container_cpu_usage_seconds_total
統計容器的 CPU 在一秒內消耗使用率,應注意的是該 container 所有的 CORE

5.container_cpu_system_seconds_total
統計容器內核態在一秒時間內消耗的 CPU

6.container_cpu_user_seconds_total
統計容器用戶態在一秒時間內消耗的 CPU

參考官方地址 https://docs.signalfx.com/en/latest/integrations/agent/monitors/cadvisor.html https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md

具體公式

1.默認如果直接使用 container_cpu_usage_seconds_total 的話,如下

sum(irate(container_cpu_usage_seconds_total{container="$Container",instance="$Node",pod="$Pod"}[5m])*100)by(pod)

默認統計的數據是該容器所有的 CORE 的平均使用率


圖片

2.如果要精確計算每個容器的 CPU 使用率,使用 % 呈現的形式,如下

sum(irate(container_cpu_usage_seconds_total{container="$Container",instance="$Node",pod="$Pod"}[5m])*100)by(pod)/sum(container_spec_cpu_quota{container="$Container",instance="$Node",pod="$Pod"}/container_spec_cpu_period{container="$Container",instance="$Node",pod="$Pod"})by(pod)

其中 container_spec_cpu_quota/container_spec_cpu_period,就代表該容器有多少個 CORE


圖片

2.參考官方 git issue
https://github.com/google/cadvisor/issues/2026#issuecomment-415819667

docker stats

docker stats 輸出的指標列是如何計算的,如下:

首先 docker stats 是通過 Docker API /containers/(id)/stats 接口來獲得 live data stream,再通過 docker stats 進行整合。

在 Linux 中使用 docker stats 輸出的內存使用率(MEM USAGE),實則該列的計算是不包含 Cache 的內存。

cache usage 在 ≤ docker 19.03 版本的 API 接口輸出對應的字段是 memory_stats.total_inactive_file,而 > docker 19.03 的版本對應的字段是 memory_stats.cache。

docker stats 輸出的 PIDS 一列代表的是該容器創建的進程或線程的數量,threads 是 Linux kernel 中的一個術語,又稱 lightweight process & kernel task

1.如何通過 Docker API 查看容器資源使用率,如下

$ curl -s --unix-socket /var/run/docker.sock "http://localhost/v1.40/containers/10f2db238edc/stats" | jq -r
{
"read": "2022-01-05T06:14:47.705943252Z",
"preread": "0001-01-01T00:00:00Z",
"pids_stats": {
"current": 240
},
"blkio_stats": {
"io_service_bytes_recursive": [
{
"major": 253,
"minor": 0,
"op": "Read",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Write",
"value": 917504
},
{
"major": 253,
"minor": 0,
"op": "Sync",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Async",
"value": 917504
},
{
"major": 253,
"minor": 0,
"op": "Discard",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Total",
"value": 917504
}
],
"io_serviced_recursive": [
{
"major": 253,
"minor": 0,
"op": "Read",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Write",
"value": 32
},
{
"major": 253,
"minor": 0,
"op": "Sync",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Async",
"value": 32
},
{
"major": 253,
"minor": 0,
"op": "Discard",
"value": 0
},
{
"major": 253,
"minor": 0,
"op": "Total",
"value": 32
}
],
"io_queue_recursive": [],
"io_service_time_recursive": [],
"io_wait_time_recursive": [],
"io_merged_recursive": [],
"io_time_recursive": [],
"sectors_recursive": []
},
"num_procs": 0,
"storage_stats": {},
"cpu_stats": {
"cpu_usage": {
"total_usage": 251563853433744,
"percpu_usage": [
22988555937059,
6049382848016,
22411490707722,
5362525449957,
25004835766513,
6165050456944,
27740046633494,
6245013152748,
29404953317631,
5960151933082,
29169053441816,
5894880727311,
25772990860310,
5398581194412,
22856145246881,
5140195759848
],
"usage_in_kernelmode": 30692640000000,
"usage_in_usermode": 213996900000000
},
"system_cpu_usage": 22058735930000000,
"online_cpus": 16,
"throttling_data": {
"periods": 10673334,
"throttled_periods": 1437,
"throttled_time": 109134709435
}
},
"precpu_stats": {
"cpu_usage": {
"total_usage": 0,
"usage_in_kernelmode": 0,
"usage_in_usermode": 0
},
"throttling_data": {
"periods": 0,
"throttled_periods": 0,
"throttled_time": 0
}
},
"memory_stats": {
"usage": 8589447168,
"max_usage": 8589926400,
"stats": {
"active_anon": 0,
"active_file": 260198400,
"cache": 1561460736,
"dirty": 3514368,
"hierarchical_memory_limit": 8589934592,
"hierarchical_memsw_limit": 8589934592,
"inactive_anon": 6947250176,
"inactive_file": 1300377600,
"mapped_file": 0,
"pgfault": 3519153,
"pgmajfault": 0,
"pgpgin": 184508478,
"pgpgout": 184052901,
"rss": 6947373056,
"rss_huge": 6090129408,
"total_active_anon": 0,
"total_active_file": 260198400,
"total_cache": 1561460736,
"total_dirty": 3514368,
"total_inactive_anon": 6947250176,
"total_inactive_file": 1300377600,
"total_mapped_file": 0,
"total_pgfault": 3519153,
"total_pgmajfault": 0,
"total_pgpgin": 184508478,
"total_pgpgout": 184052901,
"total_rss": 6947373056,
"total_rss_huge": 6090129408,
"total_unevictable": 0,
"total_writeback": 0,
"unevictable": 0,
"writeback": 0
},
"limit": 8589934592
},
"name": "/k8s_prod-xc-fund_prod-xc-fund-646dfc657b-g4px4_prod_523dcf9d-6137-4abf-b4ad-bd3999abcf25_0",
"id": "10f2db238edc13f538716952764d6c9751e5519224bcce83b72ea7c876cc0475"

2.如何計算
官方地址
https://docs.docker.com/engine/api/v1.40/#operation/ContainerStats

The???precpu_stats?? is the CPU statistic of thepreviousread, and is used to calculate the CPU usage percentage. It is not an exact copy of the??cpu_stats??? field.
If either???precpu_stats.online_cpus??? or??cpu_stats.online_cpus??? is nil then for compatibility with older daemons the length of the corresponding??cpu_usage.percpu_usage??? array should be used.
To calculate the values shown by the???stats?? command of the docker cli tool the following formulas can be used:

  • used_memory =??memory_stats.usage - memory_stats.stats.cache??
  • available_memory =??memory_stats.limit??
  • Memory usage % =??(used_memory / available_memory) * 100.0??
  • cpu_delta =??cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage??
  • system_cpu_delta =??cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage??
  • number_cpus =??lenght(cpu_stats.cpu_usage.percpu_usage)??? or??cpu_stats.online_cpus??
  • CPU usage % =??(cpu_delta / system_cpu_delta) * number_cpus * 100.0??
責任編輯:龐桂玉 來源: 奇妙的Linux世界
相關推薦

2023-04-04 09:22:50

LinuxCPU命令

2009-11-16 17:03:20

Oracle優化CPU

2024-04-11 13:27:19

Linuxtop命令

2019-01-15 15:04:54

CPU電腦使用率

2021-11-11 16:46:02

CPU使用率 .NET

2013-09-18 11:00:14

JavaCPU

2023-03-06 08:41:32

CPU使用率排查

2021-05-31 15:53:57

CPU Top命令

2021-08-10 11:45:57

topCPULinux

2020-07-08 07:00:00

LinuxCPU應用程序

2020-03-24 10:59:41

運維架構技術

2020-04-02 10:10:59

CPU系統運算

2014-12-01 13:44:03

cgroupscpulimitlinux

2010-04-27 10:32:54

Oracle優化CPU

2010-01-18 10:13:08

VB.NET獲取CPU

2009-12-15 15:12:05

Linux限制進程cp

2019-07-31 07:26:16

Linux服務器CPU

2010-02-04 10:52:54

CentOS CPU

2012-07-03 09:57:11

閏秒Linux 服務器

2009-12-22 09:23:59

Linux Sysst
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: www.yw193.com | 国产 欧美 日韩 一区 | 在线免费国产 | 久久久女 | 久久亚洲一区二区三区四区 | aaa精品 | 国产精品久久久久久久午夜片 | 久久亚洲国产精品日日av夜夜 | 九九久久久 | 一区二区三区四区视频 | 成年人在线观看 | 99久久久无码国产精品 | 在线一区视频 | 九九亚洲 | 国产免费一区二区三区网站免费 | 99爱在线观看 | 久热久 | 日韩三级精品 | 久久不卡日韩美女 | 精品无码久久久久久久动漫 | 亚洲在线 | 九九热视频这里只有精品 | 久久久久99 | 国产精品不卡一区 | 秋霞影院一区二区 | 五月婷婷在线视频 | 日韩二三区| 日本在线一二 | 99精品国自产在线观看 | 亚洲精品一区二区在线 | 精品久久久久久红码专区 | 久久9热| 久久久女女女女999久久 | 97精品一区二区 | 成人国产综合 | av手机在线播放 | 亚洲伦理自拍 | 日本一区二区在线视频 | 精品欧美 | 2022精品国偷自产免费观看 | 欧美中文字幕一区二区三区亚洲 |