要实现各种数据指标采集,需要安装不同的数据导出器,常用的导出器有node_exporter、process-exporter、blackbox_exporter,这里简单讲一下node_exporter,node_exporter安装参考上篇:https://blog.csdn.net/zcm545186061/article/details/128172488
node_exporter可以采集CPU、磁盘、内存、网络、主机信息等数据
node_exporter抓取CPU相关信息主要是各个node_cpu_seconds_total
# 几个重点指标说明
idel:空闲cpu时间
iowait:等待io的cpu时间
nice:用户空间进程内改变过优先级的进程使用cpu时间
system:内核进程使用cpu时间
user:用户进程使用cpu时间
...
这些时间加在一起即为总的cpu时间,比如idle 6480.1代表cpu 0开机以来到当前时间点,cpu 0的空闲时间是6480.1秒,用它除以总的cpu时间,就是cpu的空闲率
我们一步步来进行使用率的计算推导
increase(node_cpu_seconds_total{cpu='0', mode='idle'}[2m])
increase代表递增,该指令的意思是:cpu 0在过去两分钟内的空闲时间为115.22秒
sum(increase(node_cpu_seconds_total{mode='idle'}[2m]))/sum(increase(node_cpu_seconds_total[2m]))
一台机器可能有多个核心,sum累加各个核心的数值,该指令的意思是:过去两分钟,该机器的cpu空闲值为0.9739(四舍五入)
sum by (instance)(increase(node_cpu_seconds_total{mode='idle'}[2m]))/sum by (instance)(increase(node_cpu_seconds_total[2m]))
如果监控多台主机,要对多台主机做sum,使用sum by (instance)
得到2min内cpu使用率的计算公式:100 * (1 - sum by (instance)(increase(node_cpu_seconds_total{mode='idle'}[2m]))/sum by (instance)(increase(node_cpu_seconds_total[2m])))
count(node_cpu_seconds_total{job="node_exporter",mode='system'}) by (instance)
1) cpu负载情况
node_load1{job="node_exporter"}
node_load5{job="node_exporter"}
node_load15{job="node_exporter"}
2) cpu使用率:
(1 - sum(rate(node_cpu_seconds_total{job="node_exporter",mode="idle"}[1m])) by (instance) / sum(rate(node_cpu_seconds_total{job="node_exporter"}[1m])) by (instance) )
3) cpu 空闲模式占比:
sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter",mode="idle"}[1m])) / sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter"}[1m]))
4) cpu user模式占比:
sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter",mode="user"}[1m])) / sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter"}[1m]))
5) cpu system模式占比:
sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter",mode="system"}[1m])) / sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter"}[1m]))
6) nice 模式占比
sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter",mode="nice"}[1m])) / sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter"}[1m]))
7) iowait 模式占比
sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter",mode="iowait"}[1m])) / sum by (instance)(rate(node_cpu_seconds_total{job="node_exporter"}[1m]))
8) cpu 核数
count(node_cpu_seconds_total{job="node_exporter",mode='system'}) by (instance)
摘自:https://blog.csdn.net/lovely_nn/article/details/122131923
node_memory_xxxxxx用来抓取内存指标
node_memory_MemTotal_bytes / 1024 / 1024
,默认为kb,转化为mb需要除以两个1024
node_memory_MemFree_bytes / 1024 / 1024
,默认为kb,转化为mb需要除以两个1024
node_memory_Buffers_bytes
node_memory_Cached_bytes
node_memory_SwapFree_bytes
已用内存=可用内存 - (缓冲内存 + 缓存内存 + 空闲内存)
,即node_memory_MemTotal_bytes - (node_memory_Cached_bytes + node_memory_Buffers_bytes + node_memory_MemFree_bytes)
(1- (node_memory_Buffers_bytes + node_memory_Cached_bytes + node_memory_MemFree_bytes) / node_memory_MemTotal_bytes)
1)"/"磁盘使用率(文件系统类型为 ext.?或 xfs的)
(node_filesystem_size_bytes{job="node_exporter",fstype=~"ext.?|xfs", mountpoint="/"} - node_filesystem_free_bytes{ job="node_exporter",fstype=~"ext.?|xfs", mountpoint="/"}) / node_filesystem_size_bytes{ job="node_exporter",fstype=~"ext.?|xfs", mountpoint="/"}
2)"/"磁盘大小
node_filesystem_size_bytes{job="node_exporter",fstype=~"ext.?|xfs", mountpoint="/"}
3)"/"磁盘剩余空间
node_filesystem_free_bytes{fstype="ext4", job="node_exporter",mountpoint="/"}
4)磁盘每秒读取(1h内)
sum by (instance) (rate(node_disk_reads_completed_total{job="node_exporter"}[1h]))
5)磁盘每秒写入(1h内)
sum by (instance)(rate(node_disk_writes_completed_total{job="node_exporter"}[1h]))
6)磁盘每秒读写总数(1h内)
sum by (instance) (rate(node_disk_reads_completed_total{job="node_exporter"}[1h]))+sum by (instance)(rate(node_disk_writes_completed_total{job="node_exporter"}[1h]))
指标注释:
node_disk_writes_completed_total #成功写操作的总次数
node_disk_reads_completed_total #成功读操作的总次数
node_filesystem_size_bytes #文件系统大小
node_filesystem_free_bytes #文件系统空闲空间
摘自:https://blog.csdn.net/lovely_nn/article/details/122131923
1)上传速率:
rate(node_network_transmit_bytes_total{job="node_exporter"}[5m])
2)下载速率:
rate(node_network_receive_bytes_total{job="node_exporter"}[5m])
3)TCP连接数:
sum(time() - node_boot_time_seconds{job="node_exporter"})by(instance)
摘自:https://blog.csdn.net/lovely_nn/article/details/122131923