helpers: index subdirectories in pathtotable()
This commit is contained in:
parent
7cbf987a2a
commit
49b1b0972f
18
helpers.lua
18
helpers.lua
|
@ -11,6 +11,7 @@
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
local getmetatable = getmetatable
|
||||||
local string = {
|
local string = {
|
||||||
upper = string.upper,
|
upper = string.upper,
|
||||||
format = string.format
|
format = string.format
|
||||||
|
@ -28,14 +29,21 @@ local scroller = {}
|
||||||
|
|
||||||
-- {{{ Helper functions
|
-- {{{ Helper functions
|
||||||
-- {{{ Expose path as a Lua table
|
-- {{{ Expose path as a Lua table
|
||||||
function pathtotable(path)
|
function pathtotable(dir)
|
||||||
return setmetatable({},
|
return setmetatable({ _path = dir },
|
||||||
{ __index = function(_, name)
|
{ __index = function(table, index)
|
||||||
local f = io.open(path .. '/' .. name)
|
local path = table._path .. '/' .. index
|
||||||
|
local f = io.open(path)
|
||||||
if f then
|
if f then
|
||||||
local s = f:read("*all")
|
local s = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
return s
|
if s then
|
||||||
|
return s
|
||||||
|
else
|
||||||
|
local o = { _path = path }
|
||||||
|
setmetatable(o, getmetatable(table))
|
||||||
|
return o
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,6 @@ local function worker(format, disk)
|
||||||
|
|
||||||
local disk_lines = { [disk] = {} }
|
local disk_lines = { [disk] = {} }
|
||||||
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
|
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
|
||||||
local disk_queue = helpers.pathtotable("/sys/block/" .. disk .. "/queue")
|
|
||||||
|
|
||||||
if disk_stats.stat then
|
if disk_stats.stat then
|
||||||
local match = string.gmatch(disk_stats.stat, "[%s]+([%d]+)")
|
local match = string.gmatch(disk_stats.stat, "[%s]+([%d]+)")
|
||||||
|
@ -62,8 +61,8 @@ local function worker(format, disk)
|
||||||
helpers.uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3], unit)
|
helpers.uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3], unit)
|
||||||
|
|
||||||
-- Store I/O scheduler
|
-- Store I/O scheduler
|
||||||
if disk_queue.scheduler then
|
if disk_stats.queue.scheduler then
|
||||||
disk_usage[disk]["{sched}"] = string.gmatch(disk_queue.scheduler, "%[([%a]+)%]")
|
disk_usage[disk]["{sched}"] = string.gmatch(disk_stats.queue.scheduler, "%[([%a]+)%]")
|
||||||
end
|
end
|
||||||
|
|
||||||
return disk_usage[disk]
|
return disk_usage[disk]
|
||||||
|
|
Loading…
Reference in New Issue