Prometheus針對k8s的cadvisor監控指標


1.cAvisor簡介:
cAdvisor是Google開源的容器資源監控和性能分析工具,它是專門為容器而生,在Kubernetes中,我們不需要單獨去安裝,cAdvisor作為kubelet內置的一部分程序可以直接使用,也就是我們可以直接使用cadvisor采集數據,可以采集到和容器運行相關的所有指標,單獨安裝cAdvisor時的數據路徑為/api/v1/nodes/[節點名稱]/proxy/metrics/cadvisor,如果cadvisor集成到kubelet,采集數據的路徑是https://127.0.0.1:10250/metrics/cadvisor

2、cadvisor中獲取到的典型監控指標如下

 

指標名稱 類型 含義
container_cpu_load_average_10s gauge            過去10秒容器CPU的平均負載
container_cpu_usage_seconds_total counter  容器在每個CPU內核上的累積占用時間 (單位:秒)
container_cpu_system_seconds_total counter  System CPU累積占用時間(單位:秒)
container_cpu_user_seconds_total counter  User CPU累積占用時間(單位:秒)
container_fs_usage_bytes gauge            容器中文件系統的使用量(單位:字節)
container_fs_limit_bytes gauge            容器可以使用的文件系統總量(單位:字節)
container_fs_reads_bytes_total counter  容器累積讀取數據的總量(單位:字節)
container_fs_writes_bytes_total counter  容器累積寫入數據的總量(單位:字節)
container_memory_max_usage_bytes gauge            容器的最大內存使用量(單位:字節)
container_memory_usage_bytes gauge            容器當前的內存使用量(單位:字節)
container_spec_memory_limit_bytes gauge            容器的內存使用量限制
machine_memory_bytes  gauge            當前主機的內存總量
container_network_receive_bytes_total counter  容器網絡累積接收數據總量(單位:字節)
container_network_transmit_bytes_total counter 

容器網絡累積傳輸數據總量(單位:字節)

     
     
     
     
     

3.當能夠正常采集到cAdvisor的樣本數據后,可以通過以下表達式計算容器的CPU使用率:

(1)sum(irate(container_cpu_usage_seconds_total{image!=""}[1m])) without (cpu)
容器CPU使用率

(2)container_memory_usage_bytes{image!=""}
查詢容器內存使用量(單位:字節):

(3)sum(rate(container_network_receive_bytes_total{image!=""}[1m])) without (interface)
查詢容器網絡接收量(速率)(單位:字節/秒):

(4)sum(rate(container_network_transmit_bytes_total{image!=""}[1m])) without (interface)
容器網絡傳輸量 字節/秒

(5)sum(rate(container_fs_reads_bytes_total{image!=""}[1m])) without (device)
容器文件系統讀取速率 字節/秒

(6)sum(rate(container_fs_writes_bytes_total{image!=""}[1m])) without (device)
容器文件系統寫入速率 字節/秒

 

4.cadvisor 常用容器監控指標
(1)網絡流量
sum(rate(container_network_receive_bytes_total{name=~".+"}[1m])) by (name)
##容器網絡接收的字節數(1分鍾內),根據名稱查詢 name=~".+"

sum(rate(container_network_transmit_bytes_total{name=~".+"}[1m])) by (name)
##容器網絡傳輸的字節數(1分鍾內),根據名稱查詢 name=~".+"


(2)容器 CPU相關
sum(rate(container_cpu_system_seconds_total[1m]))
###所用容器system cpu的累計使用時間(1min鍾內)

sum(irate(container_cpu_system_seconds_total{image!=""}[1m])) without (cpu)
###每個容器system cpu的使用時間(1min鍾內)


sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100
#每個容器的cpu使用率


sum(sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100)
#總容器的cpu使用率

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM