Skip to content

Commit af979a0

Browse files
author
mutlusun
committed
read swapinfo in megabytes
1 parent 2e832bc commit af979a0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

widgets/mem_freebsd.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
local tonumber = tonumber
33
local setmetatable = setmetatable
44
local math = { floor = math.floor }
5+
local io = { popen = io.popen }
56
local helpers = require("vicious.helpers")
67
-- }}}
78

@@ -53,23 +54,20 @@ local function worker(format)
5354
_swp.total = 0
5455
_swp.buf.free = 0
5556

56-
-- Read output of swapinfo
57-
local f = io.popen("swapinfo")
57+
-- Read output of swapinfo in Mbytes
58+
local f = io.popen("swapinfo -m")
5859
-- Skip first line (table header)
5960
f:read("*line")
6061
-- Read content and sum up
6162
for line in f:lines() do
6263
local ltotal, lused, lfree = string.match(line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)")
63-
-- Add swap space in kbytes
64+
-- Add swap space in Mbytes
6465
_swp.total = _swp.total + tonumber(ltotal)
6566
_swp.inuse = _swp.inuse + tonumber(lused)
6667
_swp.buf.free = _swp.buf.free + tonumber(lfree)
6768
end
6869
f:close()
6970

70-
-- Rework into megabytes
71-
_swp.total = math.floor(_swp.total/1024)
72-
_swp.buf.free = math.floor(_swp.buf.free/1024)
7371
-- Calculate percentage
7472
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
7573
else

0 commit comments

Comments
 (0)