diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-12-15 00:25:58 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-12-15 00:25:58 +0100 |
commit | b4031d229d3fbe566c5c2c4bbb9b2a0a34b42226 (patch) | |
tree | e96f6052ef49f07d0a04c50c0d37bea8be4c8114 /dio.lua | |
parent | 2c900fa4ee6814878b7d3175ca70e112b8f656f7 (diff) | |
download | vicious-legacy-b4031d229d3fbe566c5c2c4bbb9b2a0a34b42226.tar.xz |
dio: return separated read and write statistics
This changes keys that are returned, previously only total I/O was
available in: {raw}, {kb} and {mb}. Keys returned now are (s=raw):
{total_s}, {total_kb}, {total_mb}, {read_s}, {read_kb}, {read_mb},
{write_s},{write_kb} and {write_mb}.
Diffstat (limited to 'dio.lua')
-rw-r--r-- | dio.lua | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -24,6 +24,15 @@ module("vicious.dio") local disk_usage = {} local disk_total = {} +-- {{{ Helper functions +local function uformat(array, key, value) + array["{"..key.."_s}"] = string.format("%.1f", value) + array["{"..key.."_kb}"] = string.format("%.1f", value/2) + array["{"..key.."_mb}"] = string.format("%.1f", value/2/1024) + return array +end +-- }}} + -- {{{ Disk I/O widget type local function worker(format, disk) local disk_lines = {} @@ -37,12 +46,11 @@ local function worker(format, disk) end -- Ensure tables are initialized correctly + local diff_total = {} while #disk_total < #disk_lines do table.insert(disk_total, 0) end - local diff_total = {} - for i, v in ipairs(disk_lines) do -- Diskstats are absolute, substract our last reading diff_total[i] = v - disk_total[i] @@ -51,11 +59,10 @@ local function worker(format, disk) disk_total[i] = v end - -- Calculate I/O - disk_usage["{raw}"] = diff_total[7] + diff_total[3] - -- Divide "sectors read" by 2 and 1024 to get KB and MB - disk_usage["{kb}"] = string.format("%.1f", math.floor(diff_total[7] + diff_total[3])/2) - disk_usage["{mb}"] = string.format("%.1f", math.floor(diff_total[7] + diff_total[3])/1024) + -- Calculate and store I/O + uformat(disk_usage, "read", diff_total[3]) + uformat(disk_usage, "write", diff_total[7]) + uformat(disk_usage, "total", diff_total[7] + diff_total[3]) return disk_usage end |