@@ -27,16 +27,17 @@ local disk_stats = {}
2727local disk_time = 0
2828-- Constant definitions
2929local unit = { [" s" ] = 1 , [" kb" ] = 2 , [" mb" ] = 2048 }
30+ local time_unit = { [" ms" ] = 1 , [" s" ] = 1000 }
3031
3132-- {{{ Disk I/O widget type
3233local function worker (format )
3334 local disk_lines = {}
3435
3536 for line in io.lines (" /proc/diskstats" ) do
36- local device , read , write =
37+ local device , read , write , iotime =
3738 -- Linux kernel documentation: Documentation/iostats.txt
38- string.match (line , " ([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+)" )
39- disk_lines [device ] = { read , write }
39+ string.match (line , " ([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+) %d+ %d+ (%d+)" )
40+ disk_lines [device ] = { read , write , iotime }
4041 end
4142
4243 local time = os.time ()
@@ -49,18 +50,20 @@ local function worker(format)
4950
5051 -- Check for overflows and counter resets (> 2^32)
5152 if stats [1 ] < last_stats [1 ] or stats [2 ] < last_stats [2 ] then
52- last_stats [1 ], last_stats [2 ] = stats [1 ], stats [2 ]
53+ last_stats [1 ], last_stats [2 ], last_stats [ 3 ] = stats [1 ], stats [2 ], stats [ 3 ]
5354 end
5455
5556 -- Diskstats are absolute, substract our last reading
5657 -- * divide by timediff because we don't know the timer value
5758 local read = (stats [1 ] - last_stats [1 ]) / interval
5859 local write = (stats [2 ] - last_stats [2 ]) / interval
60+ local iotime = (stats [3 ] - last_stats [3 ]) / interval
5961
6062 -- Calculate and store I/O
6163 helpers .uformat (disk_usage , device .. " read" , read , unit )
6264 helpers .uformat (disk_usage , device .. " write" , write , unit )
6365 helpers .uformat (disk_usage , device .. " total" , read + write , unit )
66+ helpers .uformat (disk_usage , device .. " iotime" , iotime , time_unit )
6467 end
6568
6669 disk_time = time
0 commit comments