aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-12-15 02:38:20 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-12-15 02:38:20 +0100
commit9150063670b94fb4350bc06d14fef630d2f57566 (patch)
treee7069b7f3cecb1d7ac33de62a140f11576d93725
parentb4031d229d3fbe566c5c2c4bbb9b2a0a34b42226 (diff)
downloadvicious-legacy-9150063670b94fb4350bc06d14fef630d2f57566.tar.xz
dio: preliminary support for multiple devices
Makes arrays for every requested disk to keep stats separated. But the whole thing with these widgets with arguments clashes with caching, and problems are to be expected.
-rw-r--r--dio.lua30
1 files changed, 17 insertions, 13 deletions
diff --git a/dio.lua b/dio.lua
index 481666b..fb2b808 100644
--- a/dio.lua
+++ b/dio.lua
@@ -6,7 +6,6 @@
-- {{{ Grab environment
local ipairs = ipairs
local setmetatable = setmetatable
-local math = { floor = math.floor }
local table = { insert = table.insert }
local helpers = require("vicious.helpers")
local string = {
@@ -35,36 +34,41 @@ end
-- {{{ Disk I/O widget type
local function worker(format, disk)
- local disk_lines = {}
+ local disk_lines = { disk = {} }
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
if disk_stats.stat then
local match = string.gmatch(disk_stats.stat, "[%s]+([%d]+)")
for i = 1, 11 do -- Store disk stats
- table.insert(disk_lines, match())
+ table.insert(disk_lines.disk, match())
end
end
-- Ensure tables are initialized correctly
- local diff_total = {}
- while #disk_total < #disk_lines do
- table.insert(disk_total, 0)
+ local diff_total = { disk = {} }
+ if not disk_total.disk then
+ disk_usage.disk = {}
+ disk_total.disk = {}
+
+ while #disk_total.disk < #disk_lines.disk do
+ table.insert(disk_total.disk, 0)
+ end
end
- for i, v in ipairs(disk_lines) do
+ for i, v in ipairs(disk_lines.disk) do
-- Diskstats are absolute, substract our last reading
- diff_total[i] = v - disk_total[i]
+ diff_total.disk[i] = v - disk_total.disk[i]
-- Store totals
- disk_total[i] = v
+ disk_total.disk[i] = v
end
-- 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])
+ uformat(disk_usage.disk, "read", diff_total.disk[3])
+ uformat(disk_usage.disk, "write", diff_total.disk[7])
+ uformat(disk_usage.disk, "total", diff_total.disk[7] + diff_total.disk[3])
- return disk_usage
+ return disk_usage.disk
end
-- }}}