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.
This commit is contained in:
parent
5cbd75996b
commit
c870691157
3
README
3
README
|
@ -177,7 +177,8 @@ vicious.widgets.fs
|
||||||
- takes an (optional) argument which, if true, includes remote file
|
- takes an (optional) argument which, if true, includes remote file
|
||||||
systems, only local file systems are included by default
|
systems, only local file systems are included by default
|
||||||
- returns a table with custom keys, using mount points as a base:
|
- 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
|
vicious.widgets.dio
|
||||||
- provides I/O statistics for requested storage devices
|
- provides I/O statistics for requested storage devices
|
||||||
|
|
27
fs.lua
27
fs.lua
|
@ -8,7 +8,10 @@
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local io = { popen = io.popen }
|
local io = { popen = io.popen }
|
||||||
local setmetatable = setmetatable
|
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")
|
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
|
-- {{{ Filesystem widget type
|
||||||
local function worker(format, nfs)
|
local function worker(format, nfs)
|
||||||
-- Fallback to listing only local file systems
|
-- Fallback to listing only local file systems
|
||||||
if nfs then nfs = "" else nfs = "--local" end
|
if nfs then nfs = "" else nfs = "--local" end
|
||||||
|
|
||||||
-- Get data from df
|
-- 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 = {}
|
local fs_info = {}
|
||||||
|
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
if not string.match(line, "^Filesystem.*") then
|
if not string.match(line, "^Filesystem.*") then
|
||||||
local size, used, avail, usep, mount = string.match(line, -- Match all (network file systems too)
|
local s, u, a, p, m = string.match(line, -- Match all at once (including NFS)
|
||||||
"^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$")
|
"^[%w%p]+[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)%%[%s]+([%w%p]+)$")
|
||||||
|
|
||||||
fs_info["{"..mount.." size}"] = tonumber(size)
|
uformat(fs_info, m .. " size", s)
|
||||||
fs_info["{"..mount.." used}"] = tonumber(used)
|
uformat(fs_info, m .. " used", u)
|
||||||
fs_info["{"..mount.." avail}"] = tonumber(avail)
|
uformat(fs_info, m .. " avail", a)
|
||||||
fs_info["{"..mount.." usep}"] = tonumber(usep)
|
fs_info["{" .. m .. " used_p}"] = tonumber(p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
|
|
Loading…
Reference in New Issue