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)在結果中只保留括號內的標簽和值


免責聲明!

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



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