diff --git a/widgets/mem_freebsd.lua b/widgets/mem_freebsd.lua index 05b0a39..66dbbaf 100644 --- a/widgets/mem_freebsd.lua +++ b/widgets/mem_freebsd.lua @@ -2,6 +2,7 @@ local tonumber = tonumber local setmetatable = setmetatable local math = { floor = math.floor } +local io = { popen = io.popen } local helpers = require("vicious.helpers") -- }}} @@ -53,23 +54,20 @@ local function worker(format) _swp.total = 0 _swp.buf.free = 0 - -- Read output of swapinfo - local f = io.popen("swapinfo") + -- Read output of swapinfo in Mbytes + local f = io.popen("swapinfo -m") -- Skip first line (table header) f:read("*line") -- Read content and sum up for line in f:lines() do local ltotal, lused, lfree = string.match(line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)") - -- Add swap space in kbytes + -- Add swap space in Mbytes _swp.total = _swp.total + tonumber(ltotal) _swp.inuse = _swp.inuse + tonumber(lused) _swp.buf.free = _swp.buf.free + tonumber(lfree) end f:close() - -- Rework into megabytes - _swp.total = math.floor(_swp.total/1024) - _swp.buf.free = math.floor(_swp.buf.free/1024) -- Calculate percentage _swp.usep = math.floor(_swp.inuse / _swp.total * 100) else