Merge pull request #25 from whirm/dio-iotime
Add iotime field to dio widget.
This commit is contained in:
commit
7ac333c571
|
@ -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**
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue