zabbix监控linux服务器的磁盘I/O

简介:

基本原理:通过分析/proc/diskstats文件,来对IO的性能进行监控。解释如下:

+++++++++++++++++++++++++++对/proc/diskstats的解释++++++++++++++++++++++++++++++++++++++++++++

[root@localhost bin]# cat /proc/diskstats | grep sda | head -1

8 0 sda 73840 10263 3178156 91219 1110085 4192562 42423152 1275861 0 447798 1366379

第一至第三个域,分别是主设备号,次设备号,设备名称

第4个域:读完成次数 ----- 读磁盘的次数,成功完成读的总次数。

(number of issued reads. This is the total number of reads completed successfully.)


第5个域:合并读完成次数, 第9个域:合并写完成次数。为了效率可能会合并相邻的读和写。从而两次4K的读在它最终被处理到磁盘上之前可能会变成一次8K的读,才被计数(和排队),因此只有一次I/O操作。这个域使你知道这样的操作有多频繁。

(number of reads merged)


第6个域:读扇区的次数,成功读过的扇区总次数。

(number of sectors read. This is the total number of sectors read successfully.)


第7个域:读花费的毫秒数,这是所有读操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。
(number of milliseconds spent reading. This is the total number of milliseconds spent by all reads (as measured from __make_request() to end_that_request_last()).)


第8个域:写完成次数 ----写完成的次数,成功写完成的总次数。

(number of writes completed. This is the total number of writes completed successfully.)


第9个域:合并写完成次数 -----合并写次数。

(number of writes merged Reads and writes which are adjacent to each other may be merged for efficiency. Thus two 4K reads may become one 8K read before it is ultimately handed to the disk, and so it will be counted (and queued) as only one I/O. This field lets you know how often this was done.)


第10个域:写扇区次数 ---- 写扇区的次数,成功写扇区总次数。

(number of sectors written. This is the total number of sectors written successfully.)


第11个域:写操作花费的毫秒数  ---  写花费的毫秒数,这是所有写操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。

(number of milliseconds spent writing This is the total number of milliseconds spent by all writes (as measured from __make_request() to end_that_request_last()).)


第12个域:正在处理的输入/输出请求数 -- -I/O的当前进度,只有这个域应该是0。当请求被交给适当的request_queue_t时增加和请求完成时减小。

(number of I/Os currently in progress. The only field that should go to zero. Incremented as requests are given to appropriate request_queue_t and decremented as they finish.)


第13个域:输入/输出操作花费的毫秒数  ----花在I/O操作上的毫秒数,这个域会增长只要field 9不为0。

(number of milliseconds spent doing I/Os. This field is increased so long as field 9 is nonzero.)


第14个域:输入/输出操作花费的加权毫秒数 -----  加权, 花在I/O操作上的毫秒数,在每次I/O开始,I/O结束,I/O合并时这个域都会增加。这可以给I/O完成时间和存储那些可以累积的提供一个便利的测量标准。

(number of milliseconds spent doing I/Os. This field is incremented at each I/O start, I/O completion, I/O merge, or read of these stats by the number of I/Os in progress (field 9) times the number of milliseconds spent doing I/O since the last update of this field. This can provide an easy measure of both I/O completion time and the backlog that may be accumulating.)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


接下来就是在zabbix agent的配置文件做操作:
vi /usr/local/zabbix/etc/zabbix_agentd.conf

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}'                    //磁盘读的次数

UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}'                     //磁盘读的毫秒数

UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}'                   //磁盘写的次数

UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}'                  //磁盘写的毫秒数

UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'            

UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}'                       //花费在IO操作上的毫秒数

UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'             //读扇区的次数(一个扇区的等于512B)

UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'          //写扇区的次数(一个扇区的等于512B)


测试命令如下:

[root@localhost bin]# ./zabbix_get -s 10.2.11.11 -p 10050 -k custom.vfs.dev.write.ops[sda]

111153

添加指标:思路:首先添加模板 ,然后在模板上添加item。
指标细节:

第一个指标Name:      Disk:$1:Read:Bytes/sec

                  Key:          custom.vfs.dev.read.sectors[sda]

                  Units:        B/sec

                  Store value: speed per second    //会进行差值计算

                  Use custom multiplier     512      //会对值乘以512,因为这里是一个扇区,转换为字节为512B

                  




同理,其他指标方式,添加如下:

第二个指标:Name:      Disk:$1:Write:Bytes/sec

                  Key:          custom.vfs.dev.write.sectors[sda]

                  Units:        B/sec

                  Store value: speed per second

                  Use custom multiplier     512

第三个指标:Name:      Disk:$1:Read:ops per second

                  Key:          custom.vfs.dev.read.ops[sda]

                  Units:        ops/second

                  Store value: speed per second

第四个指标:Name:      Disk:$1:Write:ops per second

                  Key:          custom.vfs.dev.write.ops[sda]

                  Units:        ops/second

                  Store value: speed per second

第五个指标:Name:     Disk:$1:Read:ms

                  Key:         custom.vfs.dev.read.ms[sda]

                  Units:      ms

                  Store value: speed per second

第六个指标:Name:     Disk:$1:Write:ms

                  Key:         custom.vfs.dev.write.ms[sda]

                  Units:      ms

                  Store value: speed per second










本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/1874951,如需转载请自行联系原作者

目录
相关文章
|
存储 数据挖掘 数据库
服务器数据恢复—服务器raid磁盘出现故障的数据恢复案例
一台服务器中有一组由三块SAS硬盘组建的raid阵列。服务器上部署的数据库存储在D分区,数据库备份存储在E分区。 服务器上一块硬盘指示灯显示红色。D分区不可识别。E分区虽然可以识别,但是E分区拷贝文件报错。 管理员重启服务器,先离线的硬盘上线开始同步数据,同步没有完成的情况下管理员将服务器强制关机,之后没有动过服务器。
|
弹性计算 Ubuntu 网络安全
ECS磁盘使用率异常升高,BPS,IOPS飙升
我刚开了一个2C4G的ECS,运行Ubuntu 20.04,常出现无响应、SSH断开等问题。原因是未配置swap,导致内存过高时磁盘写入频繁。解决办法在文章里。
1242 72
|
存储 监控 Linux
Linux: 检测磁盘坏块 你得会吧!
Linux: 检测磁盘坏块 你得会吧!
1287 19
Linux: 检测磁盘坏块 你得会吧!
|
Linux
在线对Linux进行磁盘扩容的技术指南。
综上所述,Linux磁盘扩容的过程,重要的不仅是技术,更是对每一步骤的深刻理解和投入的爱心。只要手握正确的工具,我们不仅能满足"孩子"的成长需求,还能享受其中的乐趣和成就。
920 10
|
监控 固态存储 Linux
如何判断Linux磁盘是SSD还是HDD?
总的来说,判断磁盘是SSD还是HDD并不复杂,只需要使用正确的命令和方法,就可以轻松得到结果。希望这些信息对你有所帮助,如果你还有其他问题,欢迎随时提问。
2250 15
|
Linux
Linux系统ext4磁盘扩容实践指南
这个过程就像是给你的房子建一个新的储物间。你需要先找到空地(创建新的分区),然后建造储物间(格式化为ext4文件系统),最后将储物间添加到你的房子中(将新的分区添加到文件系统中)。完成这些步骤后,你就有了一个更大的储物空间。
1709 10
|
存储 人工智能 运维
阿里云操作系统控制台——解决服务器磁盘I/O故障
阿里云操作系统控制台——解决服务器磁盘I/O故障
649 12
|
弹性计算 固态存储 Linux
课时4:第4天:云服务器磁盘管理
欢迎收看玩转云服务器ECS系列课程,今天我们来学习第四课:云服务器磁盘的管理。这课有三个小节。 1. 磁盘有什么用 2. 磁盘分区与挂载 3. 扩容磁盘
355 1
|
Ubuntu Linux 网络安全
Linux磁盘挂接教程
Linux磁盘挂接教程
519 14
|
存储 运维 数据挖掘
服务器数据恢复—Raid5磁盘阵列数据恢复案例
服务器数据恢复环境: 某公司一台存储上有一组由15块硬盘组建的raid5阵列。raid5阵列上层是一个xfs裸分区,起始位置是0扇区。 服务器故障: raid5阵列中有一块硬盘出现故障掉线,热备盘自动上线同步数据,数据同步还没有完成的情况下磁盘阵列中又有一块硬盘掉线,数据同步过程中断,阵列崩溃。

热门文章

最新文章