2017-12-01 00:21:33 -06:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Hagen Schink <troja84@googlemail.com>
|
|
|
|
-----------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local io = { open = io.open }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = {
|
2017-12-17 12:06:39 -06:00
|
|
|
len = string.len,
|
|
|
|
sub = string.sub,
|
|
|
|
match = string.match,
|
|
|
|
gmatch = string.gmatch
|
2017-12-01 00:21:33 -06:00
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Raid: provides state information for a requested RAID array
|
|
|
|
-- vicious.widgets.raid
|
|
|
|
local raid = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- Initialize function tables
|
|
|
|
local mddev = {}
|
|
|
|
|
|
|
|
-- {{{ RAID widget type
|
|
|
|
local function worker(format, warg)
|
2017-12-17 12:06:39 -06:00
|
|
|
if not warg then return end
|
|
|
|
mddev[warg] = {
|
|
|
|
["found"] = false,
|
|
|
|
["active"] = 0,
|
|
|
|
["assigned"] = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Linux manual page: md(4)
|
|
|
|
local f = io.open("/proc/mdstat")
|
|
|
|
for line in f:lines() do
|
|
|
|
if mddev[warg]["found"] then
|
|
|
|
local updev = string.match(line, "%[[_U]+%]")
|
|
|
|
|
|
|
|
for i in string.gmatch(updev, "U") do
|
|
|
|
mddev[warg]["active"] = mddev[warg]["active"] + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
break
|
|
|
|
elseif string.sub(line, 1, string.len(warg)) == warg then
|
|
|
|
mddev[warg]["found"] = true
|
|
|
|
|
|
|
|
for i in string.gmatch(line, "%[[%d]%]") do
|
|
|
|
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
|
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
2017-12-17 12:06:39 -06:00
|
|
|
end
|
|
|
|
f:close()
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
return {mddev[warg]["assigned"], mddev[warg]["active"]}
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return setmetatable(raid, { __call = function(_, ...) return worker(...) end })
|