read swapinfo in megabytes
This commit is contained in:
parent
2e832bc82e
commit
af979a04f7
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue