Prometheus监控K8S节点,容器 表达式计算

表达式

node exporter的一些计算语句
CPU使用率(单位为percent)
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

内存已使用(单位为bytes)
node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Buffers_bytes - node_memory_Slab_bytes

内存使用量(单位为bytes/sec)
node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Buffers_bytes - node_memory_Slab_bytes

内存使用率(单位为percent)
((node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Buffers_bytes - node_memory_Slab_bytes)/node_memory_MemTotal_bytes) * 100

192.168.61.223:9100的内存使用率(单位为percent)
((node_memory_MemTotal_bytes{instance="192.168.61.223:9100"} - node_memory_MemAvailable_bytes{instance="192.168.61.223:9100"})/node_memory_MemTotal_bytes{instance="192.168.61.223:9100"}) * 100

192.168.61.223:9100的磁盘使用率(单位为percent)
((node_filesystem_size_bytes{fstype=~"xfs|ext4",instance="192.168.61.223:9100"} - node_filesystem_free_bytes{fstype=~"xfs|ext4",instance="192.168.61.223:9100"}) / node_filesystem_size_bytes{fstype=~"xfs|ext4",instance="192.168.61.223:9100"}) * 100

uptime时间(单位为seconds)
time() - node_boot_time

192.168.61.223:9100的uptime时间(单位为seconds)
time() - node_boot_time_seconds{instance="192.168.61.223:9100"}

网络流出量(单位为bytes/sec)
irate(node_network_transmit_bytes_total{device!~"lo|bond[0-9]|cbr[0-9]|veth.*"}[5m]) > 0

192.168.61.223:9100的网络流出量(单位为bytes/sec)
irate(node_network_transmit_bytes_total{instance="192.168.61.223:9100", device!~"lo|bond[0-9]|cbr[0-9]|veth.*"}[5m]) > 0

网络流入量(单位为bytes/sec)
irate(node_network_receive_bytes_total{device!~"lo|bond[0-9]|cbr[0-9]|veth.*"}[5m]) > 0

192.168.61.223:9100的网络流入量(单位为bytes/sec)
irate(node_network_receive_bytes_total{instance="192.168.61.223:9100", device!~"lo|bond[0-9]|cbr[0-9]|veth.*"}[5m]) > 0

磁盘读取速度(单位为bytes/sec)
irate(node_disk_read_bytes_total{device=~"sd.*"}[5m])

官网文档:irate适合快速变化的计数器(counter),而rate适合缓慢变化的计数器(counter)

参考:
https://songjiayang.gitbooks.io/prometheus/content/exporter/nodeexporter_query.html

pod exporter的一些计算语句



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

全部容器的CPU使用率总和:
sum(sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100)

查询容器内存使用量(单位:字节):
container_memory_usage_bytes{image!=""}


所有容器总和:

sum(container_memory_rss{name=~".+"})
所有容器当前内存使用:
container_memory_usage_bytes{name=~".+"}
## container_memory_usage_bytes : Current memory usage in bytes.
所有容器当前内存使用总和:
sum(container_memory_usage_bytes{name=~".+"})



查询容器网络接收量速率(单位:字节/秒):
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)

容器入带宽大于50M
sum by (namespace,job,pod_name) (irate(container_network_receive_bytes_total{image!=""}[3m]))  / 1024 /1024 > 50

容器出带宽大于50M
sum by (namespace,job,pod_name) (irate(container_network_transmit_bytes_total{image!=""}[1m]))  / 1024 /1024 > 50

Prometheus基础

1.时间序列是指将同一统计指标的数值按其发生的时间先后顺序排列而成的数列

=:选择正好相等的字符串标签
!=:选择不相等的字符串标签
=~:选择匹配正则表达式的标签(或子标签)
!~:选择不匹配正则表达式的标签(或子标签)

s:seconds
m:minutes
h:hours
d:days
w:weeks
y:years

注: [1m]指过去的1分钟内

4.操作符

bool
and
or
unless
on
without : without(label)在结果中移除括号内的标签和值
by : by(label)在结果中只保留括号内的标签和值

posted @ 2020-03-07 23:53  一毛丶丶  阅读(3836)  评论(0编辑  收藏  举报