2010-03-26 00:59:01 +01:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Hagen Schink <troja84@googlemail.com>
|
|
|
|
-----------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2012-06-16 12:54:51 +02:00
|
|
|
local io = { open = io.open }
|
2010-03-26 00:59:01 +01:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = {
|
|
|
|
len = string.len,
|
|
|
|
sub = string.sub,
|
|
|
|
match = string.match,
|
|
|
|
gmatch = string.gmatch
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Raid: provides state information for a requested RAID array
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.raid
|
|
|
|
local raid = {}
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
|
2010-04-02 01:08:12 +02:00
|
|
|
-- Initialize function tables
|
|
|
|
local mddev = {}
|
|
|
|
|
2010-03-26 00:59:01 +01:00
|
|
|
-- {{{ RAID widget type
|
|
|
|
local function worker(format, warg)
|
|
|
|
if not warg then return end
|
2010-04-28 14:55:19 +02:00
|
|
|
mddev[warg] = {
|
|
|
|
["found"] = false,
|
|
|
|
["active"] = 0,
|
|
|
|
["assigned"] = 0
|
|
|
|
}
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
-- Linux manual page: md(4)
|
2012-06-18 01:30:26 +02:00
|
|
|
local f = io.open("/proc/mdstat")
|
|
|
|
for line in f:lines() do
|
2010-04-02 01:08:12 +02:00
|
|
|
if mddev[warg]["found"] then
|
2010-03-26 00:59:01 +01:00
|
|
|
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
|
2010-04-02 01:08:12 +02:00
|
|
|
mddev[warg]["found"] = true
|
2010-03-26 00:59:01 +01:00
|
|
|
|
2010-07-23 12:12:11 +02:00
|
|
|
for i in string.gmatch(line, "%[[%d]%]") do
|
2010-03-26 00:59:01 +01:00
|
|
|
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-18 01:30:26 +02:00
|
|
|
f:close()
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
return {mddev[warg]["assigned"], mddev[warg]["active"]}
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2012-06-15 18:07:05 +02:00
|
|
|
return setmetatable(raid, { __call = function(_, ...) return worker(...) end })
|