Add iotime field to dio widget.

This commit is contained in:
Elric Milon 2017-01-20 20:48:06 +01:00
parent 7aa1bac13c
commit 1b41fc2132
1 changed files with 7 additions and 4 deletions

View File

@ -27,16 +27,17 @@ local disk_stats = {}
local disk_time = 0
-- Constant definitions
local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 }
local time_unit = { ["ms"] = 1, ["s"] = 1000 }
-- {{{ Disk I/O widget type
local function worker(format)
local disk_lines = {}
for line in io.lines("/proc/diskstats") do
local device, read, write =
local device, read, write, iotime =
-- Linux kernel documentation: Documentation/iostats.txt
string.match(line, "([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+)")
disk_lines[device] = { read, write }
string.match(line, "([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+) %d+ %d+ (%d+)")
disk_lines[device] = { read, write, iotime }
end
local time = os.time()
@ -49,18 +50,20 @@ local function worker(format)
-- Check for overflows and counter resets (> 2^32)
if stats[1] < last_stats[1] or stats[2] < last_stats[2] then
last_stats[1], last_stats[2] = stats[1], stats[2]
last_stats[1], last_stats[2], last_stats[3] = stats[1], stats[2], stats[3]
end
-- Diskstats are absolute, substract our last reading
-- * divide by timediff because we don't know the timer value
local read = (stats[1] - last_stats[1]) / interval
local write = (stats[2] - last_stats[2]) / interval
local iotime = (stats[3] - last_stats[3]) / interval
-- Calculate and store I/O
helpers.uformat(disk_usage, device.." read", read, unit)
helpers.uformat(disk_usage, device.." write", write, unit)
helpers.uformat(disk_usage, device.." total", read + write, unit)
helpers.uformat(disk_usage, device.." iotime", iotime, time_unit)
end
disk_time = time