aboutsummaryrefslogtreecommitdiff
path: root/dio.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dio.lua')
-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
-- }}}