https://www.gitbook.com/book/songjiayang/prometheus/details (Prometheus in action)
https://github.com/1046102779/prometheus (Prometheus unofficial Chinese manual)
http://www.bubuko.com/infodetail-2004088.html (monitoring k8s cluster based on prometheus)
http://www.cnblogs.com/sfnz/p/6566951.html (install prometheus+grafana to monitor mysql redis kubernetes, etc., non-docker installation)
https://github.com/kayrus/prometheus- kubernetes (prometheus-kubernetes)
https://github.com/prometheus/node_exporter (prometheus/node_exporter)
http://dockone.io/article/2579 (Prometheus monitoring practice under Kubernetes)
https://github.com/prometheus/prometheus/releases (prometheus download list)
https://github.com/prometheus/node_exporter/releases/ (node_exporter download list)
Prerequisite Concepts:
1. Time series refers to a sequence of numbers in which the values of the same statistical indicator are arranged in the chronological order of their occurrence.
2.
=: select exactly equal string labels
!=: select unequal string labels
=~: selects tags (or subtags) that match the regular expression
!~: selects tags (or subtags) that do not match the regular expression
3.
s:seconds
m:minutes
h:hours
d:days
w:weeks
y:years
Note: [5m] refers to the past 5 minutes
4. Operators
bool
and
or
unless
on
without : without(label) removes parenthesized labels and values in the result
by : by(label) keeps only the labels and values in parentheses in the result
1. CPU idle rate
sum(irate(node_cpu{mode="idle", instance="134node"}[1m])) * 100 / count_scalar(node_cpu{mode="user", instance="134node"})
Notes:
## instance: refers to the label, depending on the actual configuration, regular matching can also be used
## mode : refers to the cpu mode, node-exporter has been captured, you can view it on the website of node-exporter deployment ip: 9100
For example: http://172.17.123.134:9100/metrics
##sum() function: refers to the sum of the index values in parentheses
## irate() function: refers to calculating the instantaneous (per-second) speed per second of the time series in the range vector (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负载率
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.可用内存
node_memory_MemAvailable{instance="88node"}
注释:
## node_memory_MemAvailable :Memory information field MemAvailable, node-exporter已经抓取出来,只需查询展示即可;
注意:该指标针对不同的系统是采集不同的,CentOS6.X 上就采集不到这个指标;CentOS7上可以;
4.空闲文件系统空间
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 :
node_memory_SwapFree{instance="134node"}
## node_memory_SwapTotal: Memory information field SwapTotal.
## swap :类似于可以把硬盘当内存用,那么这一部分内存一般就叫做swap
Swap Usage :
node_memory_SwapTotal{instance="134node"} - node_memory_SwapFree{instance="134node"}
## node_memory_SwapFree: Memory information field SwapFree
Swap I/O(in):
rate(node_vmstat_pswpin{instance="88node"}[1m]) * 4096 or irate(node_vmstat_pswpin{instance="88node"}[5m]) * 4096
Swap I/O(out):
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使用率
avg without (cpu) (irate(node_cpu{instance="88node", mode!="idle"}[5m]))
## avg : 平均值
7.网路使用情况
上传速率:
irate(node_network_transmit_bytes{device!="lo",instance="88node"}[1m])
下载速率:
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"}
可用内存占比:
(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分钟内)
sum by (instance) (irate(node_disk_reads_completed{instance="88node"}[5m]))
##node_disk_reads_completed: The total number of reads completed successfully
磁盘每秒写入(5分钟内)
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分钟内)
sum by (instance) (irate(node_disk_io_time_ms{instance="88node"}[5m]))
##node_disk_io_time_ms: Total Milliseconds spent doing I/Os
磁盘每秒读写总数(5分钟内)
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分钟内)
sum(irate(node_disk_bytes_read{instance="88node"}[1m]))
##node_disk_bytes_read : The total number of bytes read successfully(成功读取的字节数)
磁盘写入总数(1分钟内)
sum(irate(node_disk_bytes_written{instance="88node"}[1m]))
##node_disk_bytes_written :The total number of bytes written successfully(成功写入的字节数)
使用I/O的毫秒数(1分钟内)
sum(irate(node_disk_io_time_ms{instance="88node"}[1m]))
##node_disk_io_time_ms :Total Milliseconds spent doing I/Os.(使用IO的总毫秒数)
11.文件系统空闲空间
最低值:
min(node_filesystem_free{fstype=~"xfs|ext4",instance="88node"} / node_filesystem_size{fstype=~"xfs|ext4",instance="88node"})
最高值:
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 is a 64-bit file system that supports a single file system of up to 8EB minus 1 byte. The actual deployment depends on the host operating system
The maximum block limit of the system. For a 32-bit linux system, the file and file system size is limited to 16TB.