MENU

PromQL监控指标

• 2021 年 06 月 04 日 • Prometheus,监控分析

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

指标名称类型含义
container_cpu_load_average_10sgauge过去10秒容器CPU的平均负载
container_cpu_usage_seconds_totalcounter容器在每个CPU内核上的累积占用时间 (单位:秒)
container_cpu_system_seconds_totalcounterSystem CPU累积占用时间(单位:秒)
container_cpu_user_seconds_totalcounterUser 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_bytesgauge当前主机的内存总量
container_network_receive_bytes_totalcounter容器网络累积接收数据总量(单位:字节)
container_network_transmit_bytes_totalcounter容器网络累积传输数据总量(单位:字节)

表达式计算容器的CPU使用率

容器CPU使用率
sum(irate(container_cpu_usage_seconds_total{image!=""}[1m])) without (cpu)
查询容器内存使用量(单位:字节):
container_memory_usage_bytes{image!=""}
查询容器网络接收量(速率)(单位:字节/秒):
sum(rate(container_network_receive_bytes_total{image!=""}[1m])) without (interface)
容器网络传输量 字节/秒
sum(rate(container_network_transmit_bytes_total{image!=""}[1m])) without (interface)
容器文件系统读取速率 字节/秒
sum(rate(container_fs_reads_bytes_total{image!=""}[1m])) without (device)
容器文件系统写入速率 字节/秒
sum(rate(container_fs_writes_bytes_total{image!=""}[1m])) without (device)     

cadvisor 常用容器监控指标

网络流量
容器网络接收的字节数(1分钟内),根据名称查询 name=~".+"
sum(rate(container_network_receive_bytes_total{name=~".+"}[1m])) by (name)
容器网络传输的字节数(1分钟内),根据名称查询 name=~".+"
sum(rate(container_network_transmit_bytes_total{name=~".+"}[1m])) by (name)
容器 CPU相关
所用容器system cpu的累计使用时间(1min钟内)
sum(rate(container_cpu_system_seconds_total[1m]))
每个容器system cpu的使用时间(1min钟内)
sum(irate(container_cpu_system_seconds_total{image!=""}[1m])) without (cpu)
每个容器的cpu使用率
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)

常见的监控指标

node_boot_time系统启动时间
node_cpu系统CPU使用量
nodedisk磁盘IO
nodefilesystem文件系统用量
node_load1系统负载
nodememeory内存使用量
nodenetwork网络带宽
node_time当前系统时间
go_node exporter中go相关指标
process_node exporter自身进程相关运行指标

PromQL语句查询监控数据

rate(node_cpu_seconds_total[1m])
使用without表达式,可以将标签CPU去除后聚合数据即可
avg without(cpu) (rate(node_cpu_seconds_total[1m]))
那如果需要计算系统CPU的总体使用率,通过排除系统闲置的CPU使用率即可获得
1 - avg without(cpu) (rate(node_cpu_seconds_total{mode="idle"}[1m]))

PromQL总结

PromQL是Prometheus的查询语言,通过PromQL我们可以对数据进行查询,过滤,以及聚合,计算等操作。

Kubernetes中的各种资源指标在1min钟之内的请求速率
sum(rate(apiserver_request_count[1m])) by (resource, subresource, verb)
1分钟的错误率和请求率的比率
rate(apiserver_request_count{code=~"^(?:5..)$"}[1m]) /
rate(apiserver_request_count[1m])
请求次数:对服务的请求、来自哪里、到哪个服务、哪个操作以及是否成功
apiserver_request_total
获得所有成功的请求,状态码是200的请求总数
sum(rate(apiserver_request_total{job="kubernetes-apiserver",code=~"2.."}[5m]))
获取状态码是400或者500的请求总数
sum(rate(apiserver_request_total{job="kubernetes-apiserver",code=~"[45].."}[5m]))
请求耗时时间
apiserver_request_duration_seconds