diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-18 00:52:55 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-18 00:52:55 +0100 |
commit | c870691157ee542abec9a177ef64a8bade31580c (patch) | |
tree | 3049fb6f8863680c158cee915c07045636e0529f | |
parent | 5cbd75996be3536672cbd2b1c5166c3ce7238f30 (diff) | |
download | vicious-legacy-c870691157ee542abec9a177ef64a8bade31580c.tar.xz |
fs: switched to 1K blocks and new keys
Previous version could return 1 on one update and 900 on the next (1st
being GB, 2nd MB) a user appending "GB" to the value suddenly has a
900GB disk available. Returned keys are now: size_mb, size_gb,
used_mb, used_gb, avail_mb, avail_gb, and percentage is now: used_p.
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | fs.lua | 27 |
2 files changed, 21 insertions, 9 deletions
@@ -177,7 +177,8 @@ vicious.widgets.fs - takes an (optional) argument which, if true, includes remote file systems, only local file systems are included by default - returns a table with custom keys, using mount points as a base: - {/ size}, {/ used}, {/ avail}, {/ usep}, {/home size} etc. + {/ size_mb}, {/ size_gb}, {/ used_mb}, {/ used_gb}, {/ used_p}, + {/ avail_mb}, {/ avail_gb}, {/home size_mb} etc. vicious.widgets.dio - provides I/O statistics for requested storage devices @@ -8,7 +8,10 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable -local string = { match = string.match } +local string = { + match = string.match, + format = string.format +} -- }}} @@ -16,24 +19,32 @@ local string = { match = string.match } module("vicious.fs") +-- {{{ Helper functions +local function uformat(array, key, value) + array["{"..key.."_mb}"] = string.format("%.1f", value/1024) + array["{"..key.."_gb}"] = string.format("%.1f", value/1024/1024) + return array +end +-- }}} + -- {{{ Filesystem widget type local function worker(format, nfs) -- Fallback to listing only local file systems if nfs then nfs = "" else nfs = "--local" end -- Get data from df - local f = io.popen("LANG=C df -hP " .. nfs) + local f = io.popen("LANG=C df -kP " .. nfs) local fs_info = {} for line in f:lines() do if not string.match(line, "^Filesystem.*") then - local size, used, avail, usep, mount = string.match(line, -- Match all (network file systems too) - "^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$") + local s, u, a, p, m = string.match(line, -- Match all at once (including NFS) + "^[%w%p]+[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)%%[%s]+([%w%p]+)$") - fs_info["{"..mount.." size}"] = tonumber(size) - fs_info["{"..mount.." used}"] = tonumber(used) - fs_info["{"..mount.." avail}"] = tonumber(avail) - fs_info["{"..mount.." usep}"] = tonumber(usep) + uformat(fs_info, m .. " size", s) + uformat(fs_info, m .. " used", u) + uformat(fs_info, m .. " avail", a) + fs_info["{" .. m .. " used_p}"] = tonumber(p) end end f:close() |