diff --git a/README.md b/README.md index f71f925..36720f9 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ Supported platforms: Linux. - Returns: * returns a table with string keys: `{sda total_s}`, `{sda total_kb}`, `{sda total_mb}`, `{sda read_s}`, `{sda read_kb}`, `{sda read_mb}`, `{sda write_s}`, - `{sda write_kb}`, `{sda write_mb}`, `{sdb1 total_s}` etc. + `{sda write_kb}`, `{sda write_mb}`, `{sda iotime_ms}`, `{sda iotime_s}`, `{sdb1 total_s}` etc. **vicious.widget.fanspeed** diff --git a/widgets/dio_linux.lua b/widgets/dio_linux.lua index b73cd21..82fa50f 100644 --- a/widgets/dio_linux.lua +++ b/widgets/dio_linux.lua @@ -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