1、說明html
最近使用Prometheus新搭建監控系統時候發現內存採集時centos6和centos7下內存監控指標採集計算公式不相同,最後採用統一計算方法並整理計算公式以下:node
1
|
100-(node_memory_MemFree_bytes+node_memory_Cached_bytes+node_memory_Buffers_bytes)
/node_memory_MemTotal_bytes
*10
|
2、node-exporter經常使用指標含義(參考文檔)mysql
https://www.gitbook.com/book/songjiayang/prometheus/details (Prometheus 實戰) linux
https://github.com/1046102779/prometheus (Prometheus 非官方中文手冊)git
http://www.bubuko.com/infodetail-2004088.html (基於prometheus監控k8s集羣)github
http://www.cnblogs.com/sfnz/p/6566951.html (安裝prometheus+grafana監控mysql redis kubernetes等,非docker安裝)正則表達式
https://github.com/kayrus/prometheus-kubernetes (prometheus-kubernetes) redis
https://github.com/prometheus/node_exporter (prometheus/node_exporter)sql
http://dockone.io/article/2579 ( Prometheus在Kubernetes下的監控實踐)docker
https://github.com/prometheus/prometheus/releases (prometheus 下載列表)
https://github.com/prometheus/node_exporter/releases/ (node_exporter下載列表)
前提概念:
1.時間序列是指將同一統計指標的數值按其發生的時間前後順序排列而成的數列
2.表達式
=:選擇正好相等的字符串標籤
!=:選擇不相等的字符串標籤
=~:選擇匹配正則表達式的標籤(或子標籤)
!~:選擇不匹配正則表達式的標籤(或子標籤)
3.時間定義
s:seconds
m:minutes
h:hours
d:days
w:weeks
y:years
注: [5m]指過去的5分鐘內
4.操做符
bool
and
or
unless
on
without : without(label)在結果中移除括號內的標籤和值
by : by(label)在結果中只保留括號內的標籤和值
1.CPU空閒率
1
|
sum
(irate(node_cpu{mode=
"idle"
, instance=
"134node"
}[1m])) * 100 / count_scalar(node_cpu{mode=
"user"
, instance=
"134node"
})
|
註釋:
## instance:指的是label,具體根據實際配置,也可用正則匹配
## mode : 指cpu模式,node-exporter已經抓取出來,能夠在node-exporter部署ip:9100這個網址上查看
例如:http://172.17.123.134:9100/metrics
## sum()函數: 指將括號內的指標值求和
## irate()函數: 指計算範圍向量中時間序列的每秒鐘的瞬時(per-second)速度(calculates the
per-second instant rate of increase of the time series in the range vector)
## count_scalar()函數 : 指將時間序列向量中的元素個數做爲標量返回(returns the number of
elements in a time series vector as a scalar)
2.CPU負載率
1
|
node_load1{instance=
"134node"
} / count by(job, instance)(count by(job, instance, cpu)(node_cpu{instance=
"134node"
}))
|
註釋:
## node_load1 : 指1分鐘內cpu平均負載,一樣cpu_load5指5分鐘內cpu平均負載,cpu_load15指15
分鐘內cpu平均負載
## count : 指聚合向量中的每一個元素(即計數)
## 待添加後續註解
3.可用內存
1
|
node_memory_MemAvailable{instance=
"88node"
}
|
註釋:
## node_memory_MemAvailable :Memory information field MemAvailable, node-exporter已經抓取出來,只需查詢展現便可;
注意:該指標針對不一樣的系統是採集不一樣的,CentOS6.X 上就採集不到這個指標;CentOS7上能夠;
4.空閒文件系統空間
1
2
3
|
sum
(node_filesystem_free{fstype=
"xfs"
,instance=
"88node"
})
sum
(node_filesystem_free{fstype=
"ext4"
,instance=
"134node"
})
|
## node_filesystem_free: Filesystem free space in bytes
## fstype 有以下種類:
## aufs : 指聯合文件系統,用來把本來分離的兩個文件系統聯合在一塊兒
## cgroup : Cgroups(控制組)是Linux內核的一個功能,用來限制、統計和分離一個進程組的資源
(CPU、內存、磁盤輸入輸出等)。
## tmpfs : tmpfs是一種虛擬內存文件系統,而不是塊設備。
## overlay : 一個 overlay 文件系統包含兩個文件系統,一個 upper 文件系統和一個 lower 文件系
統,是一種新型的聯合文件系統
### proc、xfs、mqueue等等。
5.swap硬盤交換區:從硬盤到內存或從內存到硬盤,虛擬內存交換
Swap free :
1
|
node_memory_SwapFree{instance=
"134node"
}
|
## node_memory_SwapTotal: Memory information field SwapTotal.
## swap :相似於能夠把硬盤當內存用,那麼這一部份內存通常就叫作swap
Swap Usage :
1
|
node_memory_SwapTotal{instance=
"134node"
} - node_memory_SwapFree{instance=
"134node"
}
|
## node_memory_SwapFree: Memory information field SwapFree
Swap I/O(in):
1
|
rate(node_vmstat_pswpin{instance=
"88node"
}[1m]) * 4096 or irate(node_vmstat_pswpin{instance=
"88node"
}[5m]) * 4096
|
Swap I/O(out):
1
|
rate(node_vmstat_pswpout{instance=
"88node"
}[1m]) * 4096 or irate(node_vmstat_pswpout{instance=
"88node"
}[5m]) * 4096
|
## vmstat :vmstat命令是最多見的Linux/Unix監控工具,能夠展示給定時間間隔的服務器的狀態值,
包括服務器的CPU使用率,內存使用,虛擬內存交換狀況,IO讀寫狀況。
## pswpin/s:每秒從硬盤交換區傳送進入內存的次數。
## pswpout/s:每秒從內存傳送到硬盤交換區的次數。
## pswpin/s、 pswpout/s描述的是與硬盤交換區相關的交換活動。交換關係到系統的效率。交換區在
硬盤上對硬盤的讀,寫操做比內存讀,寫慢得多,所以,爲了提升系統效率就應該設法減小交換。
一般的做法就是加大內存,使交換區中進行的交換活動爲零,或接近爲零。若是swpot/s的值大
於 1,預示可能須要增長內存或減小緩衝區(減小緩衝區可以釋放一部分自由內存空間)。
Swap free 率(百分百)
(node_memory_SwapFree{instance=~"$server"} /node_memory_SwapTotal{instance=~"$server"}) * 100
6.CPU使用率
1
|
avg without (cpu) (irate(node_cpu{instance=
"88node"
, mode!=
"idle"
}[5m]))
|
## avg : 平均值
7.網路使用狀況
上傳速率:
1
|
irate(node_network_transmit_bytes{device!=
"lo"
,instance=
"88node"
}[1m])
|
下載速率:
1
|
irate(node_network_receive_bytes{device!=
"lo"
,instance=
"88node"
}[1m])
|
## eth0: ethernet的簡寫,通常用於以太網接口。
## wifi0:wifi是無線局域網,所以wifi0通常指無線網絡接口。
## ath0: Atheros的簡寫,通常指Atheros芯片所包含的無線網絡接口。
## tunl0:tunl0是隧道接口,封裝數據的時候使用
## lo: local的簡寫,通常指本地環回接口。
8.內存使用率
已用內存:(總內存-空閒內存-緩存=已使用內存)
node_memory_MemTotal{instance="88node"} -
node_memory_MemFree{instance="88node"} -
node_memory_Cached{instance="88node"} -
node_memory_Buffers{instance="88node"} -
node_memory_Slab{instance="88node"}
Buffer緩存:
node_memory_Buffers{instance="88node"}
Cached緩存:
node_memory_Cached{instance="88node"}
+ node_memory_Slab{instance="88node"}
Free空閒內存:
node_memory_MemFree{instance="88node"}
可用內存佔比:
1
2
3
|
(node_memory_MemAvailable{instance=
"88node"
} /
node_memory_MemTotal{instance=
"88node"
}) * 100
|
## total:總計物理內存的大小。
## Free:空閒內存有多少。
## Shared:多個進程共享的內存總額。
## Buffers:表示buffers cache的內存數量,通常對塊設備的讀寫才須要緩衝
## Cached:表示page cached的內存數量,通常做文件系統的cached,頻繁訪問的文件都會被
cached。若是cached值較大,就說明cached文件數較多。若是此時IO中的bi比較小,就
說明文件系統效率比較好
## Slab:slab分配器不只能夠提供動態內存的管理功能,並且能夠做爲常常分配並釋放的內存的緩存
## MemAvailable: Free + Buffers + Cached - 不可回收的部分。不可回收部分包括:共享內存段,
tmpfs,ramfs等
9.磁盤讀寫(IOPs)
磁盤每秒讀取(5分鐘內)
1
|
sum
by (instance) (irate(node_disk_reads_completed{instance=
"88node"
}[5m]))
|
##node_disk_reads_completed: The total number of reads completed successfully
磁盤每秒寫入(5分鐘內)
1
|
sum
by (instance)(irate(node_disk_writes_completed{instance=
"88node"
}[5m]))
|
##node_disk_writes_completed :The total number of writes completed successfully.
使用I/O的毫秒數(5分鐘內)
1
|
sum
by (instance) (irate(node_disk_io_time_ms{instance=
"88node"
}[5m]))
|
##node_disk_io_time_ms: Total Milliseconds spent doing I/Os
磁盤每秒讀寫總數(5分鐘內)
1
|
sum
by (instance) (irate(node_disk_reads_completed{instance=
"88node"
}[5m])) +
sum
by (instance) (irate(node_disk_writes_completed{instance=
"88node"
}[5m]))
|
10.I/O Usage
磁盤讀取總數(1分鐘內)
1
|
sum
(irate(node_disk_bytes_read{instance=
"88node"
}[1m]))
|
##node_disk_bytes_read : The total number of bytes read successfully(成功讀取的字節數)
磁盤寫入總數(1分鐘內)
1
|
sum
(irate(node_disk_bytes_written{instance=
"88node"
}[1m]))
|
##node_disk_bytes_written :The total number of bytes written successfully(成功寫入的字節數)
使用I/O的毫秒數(1分鐘內)
1
|
sum
(irate(node_disk_io_time_ms{instance=
"88node"
}[1m]))
|
##node_disk_io_time_ms :Total Milliseconds spent doing I/Os.(使用IO的總毫秒數)
11.文件系統空閒空間
最低值:
1
|
min(node_filesystem_free{fstype=~
"xfs|ext4"
,instance=
"88node"
} / node_filesystem_size{fstype=~
"xfs|ext4"
,instance=
"88node"
})
|
最高值:
1
|
max(node_filesystem_free{fstype=~
"xfs|ext4"
,instance=
"88node"
} / node_filesystem_size{fstype=~
"xfs|ext4"
,instance=
"88node"
})
|
## ext4是第四代擴展文件系統(英語:Fourth EXtended filesystem,縮寫爲ext4)是linlli
linux下的日誌文件系統,ext4的文件系統容量達到1EB,而文件容量則達到16TB
## XFS是一個64位文件系統,最大支持8EB減1字節的單個文件系統,實際部署時取決於宿主操做系
統的最大塊限制。對於一個32位linux系統,文件和文件系統的大小會被限制在16TB。原文:https://blog.csdn.net/ffzhihua/article/details/88131507