文章目录
- 1./proc/diskstats简介
- 2./proc/diskstats具体内容如下
- 3.磁盘IO操作百分比
1./proc/diskstats简介
- /proc/diskstats 文件中,包含了设备相关的信息,即磁盘相关的信息,以文件形式保存。
- 除正在处理的输入/输出请求数这项是非累积值外,其他磁盘统计都是累积值。
- zabbix中磁盘使用情况就是从diskstats采集。
- 什么是块设备?
(1)块设备里面存储的数据,可以随机访问,硬盘、光盘、U盘等,通常以块为单位的进行存取,块这个概念是操作系统层面的,落实到硬盘其实硬盘存取数据的最小单位是扇区(512字节),块通常是由1个或多个扇区组成。
(2)相对于块设备,还存在字符设备,其不能随机跳跃式读取。
2./proc/diskstats具体内容如下
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
1 3 ram3 0 0 0 0 0 0 0 0 0 0 0
1 4 ram4 0 0 0 0 0 0 0 0 0 0 0
1 5 ram5 0 0 0 0 0 0 0 0 0 0 0
1 6 ram6 0 0 0 0 0 0 0 0 0 0 0
1 7 ram7 0 0 0 0 0 0 0 0 0 0 0
1 8 ram8 0 0 0 0 0 0 0 0 0 0 0
1 9 ram9 0 0 0 0 0 0 0 0 0 0 0
1 10 ram10 0 0 0 0 0 0 0 0 0 0 0
1 11 ram11 0 0 0 0 0 0 0 0 0 0 0
1 12 ram12 0 0 0 0 0 0 0 0 0 0 0
1 13 ram13 0 0 0 0 0 0 0 0 0 0 0
1 14 ram14 0 0 0 0 0 0 0 0 0 0 0
1 15 ram15 0 0 0 0 0 0 0 0 0 0 0
7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
7 2 loop2 0 0 0 0 0 0 0 0 0 0 0
7 3 loop3 0 0 0 0 0 0 0 0 0 0 0
7 4 loop4 0 0 0 0 0 0 0 0 0 0 0
7 5 loop5 0 0 0 0 0 0 0 0 0 0 0
7 6 loop6 0 0 0 0 0 0 0 0 0 0 0
7 7 loop7 0 0 0 0 0 0 0 0 0 0 0
252 0 vda 9585497 1982845 536785922 270901280 106708307 438802239 4369057904 1693205040 0 439098969 1970941101
252 1 vda1 9584936 1982626 536779682 270899348 106674766 438802239 4369057896 1692048644 0 438849123 1969781937
- ram0~ram15设备是什么?
ram0~ram15是RamDisk,将内存的一部分当做硬盘(Disk)来使用。RamDisk有固定的大小,可以像正常硬盘分区那样去使用。 就操作时间来讲,RamDisk比真实的物理硬盘快很多,当系统关闭或断电时,保存在RamDisk中的数据会全部丢失。RamDisk可以成为一个存放临时数据的好地方。 - loop0~loop7设备是什么?
loop设备,是一种伪设备,是通过利用文件来模拟块设备的一种方式。 - 每一列,从左往后,字段描述如下:
1设备号 | 2次设备号 | 3设备名称 | 4读完成数 | 5合并读完成数 | 6读扇区次数 | 7读操作花费毫秒数 | 8写完成次数 | 9合并写完成次数 | 10写扇区次数 | 11写操作花费的毫秒数 | 12正在处理的输入/输出请求数 | 13输入/输出操作花费的毫秒数 | 14输入/输出操作花费的加权毫秒数 |
1 | 0 | ram0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
252 | 1 | vd1 | 9584936 | 1982626 | 536779682 | 270899348 | 106674766 | 438802239 | 4369057896 | 1692048644 | 0 | 438849123 | 1969781937 |
- 可以参考
/sys/block/device_name/stat的输出和上面各个字段是一样的。
The /proc/diskstats file displays the I/O statistics
of block devices. Each line contains the following 14
fields:
1 - major number
2 - minor mumber
3 - device name
4 - reads completed successfully
5 - reads merged
6 - sectors read
7 - time spent reading (ms)
8 - writes completed
9 - writes merged
10 - sectors written
11 - time spent writing (ms)
12 - I/Os currently in progress
13 - time spent doing I/Os (ms)
14 - weighted time spent doing I/Os (ms)
第一列为 设备号
(number of issued reads. This is the total number of reads completed successfully.)
第二列为 次设备号
(number of reads merged)
第三列为 设备名称
(number of sectors read. This is the total number of sectors read successfully.)
第四列为 成功完成读的总次数
(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()).)
第五列为 合并读次数,为了效率可能会合并相邻的读和写,从而两次4K的读在它最终被处理到磁盘上之前可能会变成一次8K的读,才被计数(和排队),因此只有一次I/O操作。
(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.)
第六列为 读扇区的次数
第七列为 读花的时间(ms),这是所有读操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)
第八列到第十一列分别是写
第十二列为 I/O的当前进度,只有这个域应该是0,如果这个值为0,同时write_complete read_complete io_processing 一直不变可能就就是IO hang了。
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.)
第十三列为 输入输入花的时间(ms),花在I/O操作上的毫秒数,这个域会增长只要field 9不为0。
(number of milliseconds spent doing I/Os. This field is increased so long as field 9 is nonzero.)
第十四列为 输入/输出操作花费的加权毫秒数,
(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.)
3.磁盘IO操作百分比
- 如何计算磁盘IO操作百分比
采样两个足够短的时间间隔的磁盘快照,标记为t1、t2,计算t1时间的输入/输出操作花费的毫秒数used1,计算t2时间的输入/输出操作花费的毫秒数used2。
于是磁盘IO操作百分比为:
100 * (used2 - used1)/ (t2 - t1)
参考:
https://blog.51cto.com/tryagaintry/1975943;
http://www.findme.wang/share/detail/id/678.html;
https://blog.51cto.com/tryagaintry/1975943;