read swapinfo in megabytes

This commit is contained in:
mutlusun 2018-06-20 22:53:16 +02:00
parent 2e832bc82e
commit af979a04f7
1 changed files with 4 additions and 6 deletions

View File

@ -2,6 +2,7 @@
local tonumber = tonumber local tonumber = tonumber
local setmetatable = setmetatable local setmetatable = setmetatable
local math = { floor = math.floor } local math = { floor = math.floor }
local io = { popen = io.popen }
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
-- }}} -- }}}
@ -53,23 +54,20 @@ local function worker(format)
_swp.total = 0 _swp.total = 0
_swp.buf.free = 0 _swp.buf.free = 0
-- Read output of swapinfo -- Read output of swapinfo in Mbytes
local f = io.popen("swapinfo") local f = io.popen("swapinfo -m")
-- Skip first line (table header) -- Skip first line (table header)
f:read("*line") f:read("*line")
-- Read content and sum up -- Read content and sum up
for line in f:lines() do for line in f:lines() do
local ltotal, lused, lfree = string.match(line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)") 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.total = _swp.total + tonumber(ltotal)
_swp.inuse = _swp.inuse + tonumber(lused) _swp.inuse = _swp.inuse + tonumber(lused)
_swp.buf.free = _swp.buf.free + tonumber(lfree) _swp.buf.free = _swp.buf.free + tonumber(lfree)
end end
f:close() f:close()
-- Rework into megabytes
_swp.total = math.floor(_swp.total/1024)
_swp.buf.free = math.floor(_swp.buf.free/1024)
-- Calculate percentage -- Calculate percentage
_swp.usep = math.floor(_swp.inuse / _swp.total * 100) _swp.usep = math.floor(_swp.inuse / _swp.total * 100)
else else