aboutsummaryrefslogtreecommitdiff
path: root/widgets/raid.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-26 00:59:01 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-26 00:59:01 +0100
commita9347ec0d033aa08d77fcc75c35d88514f9e84f5 (patch)
treeb2d2bc3a3d31e55dc2eb453517caa9db1fe37bc7 /widgets/raid.lua
parent9af29ce1e642070b6ed9fdf02155d37838323790 (diff)
downloadvicious-legacy-a9347ec0d033aa08d77fcc75c35d88514f9e84f5.tar.xz
raid: import raid state widget type by Hagen
This widget type returns 1st value as the number of assigned, and 2nd as active, devices in the array provided as the widget argument.
Diffstat (limited to 'widgets/raid.lua')
-rw-r--r--widgets/raid.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/widgets/raid.lua b/widgets/raid.lua
new file mode 100644
index 0000000..eaf7825
--- /dev/null
+++ b/widgets/raid.lua
@@ -0,0 +1,56 @@
+-----------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2010, Hagen Schink <troja84@googlemail.com>
+-----------------------------------------------------
+
+-- {{{ Grab environment
+local io = { lines = io.lines }
+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
+module("vicious.widgets.raid")
+
+
+-- {{{ RAID widget type
+local function worker(format, warg)
+ if not warg then return end
+
+ local found = false
+ local mddev = {}
+ mddev[warg] = {
+ ["active"] = 0,
+ ["assigned"] = 0
+ }
+
+ -- Linux manual page: md(4)
+ for line in io.lines("/proc/mdstat") do
+ if 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
+ found = true
+
+ for i in string.gmatch(line, "%[%d%]") do
+ mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
+ end
+ end
+ end
+
+ return {mddev[warg]["assigned"], mddev[warg]["active"]}
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })