cAvisor简介

cAdvisor是Google开源的容器资源监控和性能分析工具,它是专门为容器而生,在Kubernetes中,我们不需要单独去安装,cAdvisor作为kubelet内置的一部分程序可以直接使用,也就是我们可以直接使用cadvisor采集数据,可以采集到和容器运行相关的所有指标,单独安装cAdvisor时的数据路径为/api/v1/nodes/[节点名称]/proxy/metrics/cadvisor,如果cadvisor集成到kubelet,采集数据的路径是https://127.0.0.1:10250/metrics/cadvisor

cadvisor中获取到的典型监控指标如下:

指标名称类型含义
container_cpu_load_average_10sgauge           过去10秒容器CPU的平均负载
container_cpu_usage_seconds_totalcounter 容器在每个CPU内核上的累积占用时间 (单位:秒)
container_cpu_system_seconds_totalcounter System CPU累积占用时间(单位:秒)
container_cpu_user_seconds_totalcounter User CPU累积占用时间(单位:秒)
container_fs_usage_bytesgauge           容器中文件系统的使用量(单位:字节)
container_fs_limit_bytesgauge           容器可以使用的文件系统总量(单位:字节)
container_fs_reads_bytes_totalcounter 容器累积读取数据的总量(单位:字节)
container_fs_writes_bytes_totalcounter 容器累积写入数据的总量(单位:字节)
container_memory_max_usage_bytesgauge           容器的最大内存使用量(单位:字节)
container_memory_usage_bytesgauge           容器当前的内存使用量(单位:字节)
container_spec_memory_limit_bytesgauge           容器的内存使用量限制
machine_memory_bytes gauge           当前主机的内存总量
container_network_receive_bytes_totalcounter 容器网络累积接收数据总量(单位:字节)
container_network_transmit_bytes_totalcounter 

容器网络累积传输数据总量(单位:字节)

 当能够正常采集到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)
容器文件系统写入速率 字节/秒

cadvisor 常用容器监控指标


网络流量
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=~".+"


容器 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使用率

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐