| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
local io = { lines = io.lines } |
| 24 |
local math = { floor = math.floor } |
| 25 |
local string = { gmatch = string.gmatch } |
| 26 |
local helpers = require"vicious.helpers" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
return helpers.setcall(function () |
| 31 |
local _mem = { buf = {}, swp = {} } |
| 32 |
|
| 33 |
|
| 34 |
for line in io.lines("/proc/meminfo") do |
| 35 |
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do |
| 36 |
if k == "MemTotal" then _mem.total = math.floor(v/1024) |
| 37 |
elseif k == "MemFree" then _mem.buf.f = math.floor(v/1024) |
| 38 |
elseif k == "MemAvailable" then _mem.buf.a = math.floor(v/1024) |
| 39 |
elseif k == "Buffers" then _mem.buf.b = math.floor(v/1024) |
| 40 |
elseif k == "Cached" then _mem.buf.c = math.floor(v/1024) |
| 41 |
elseif k == "SwapTotal" then _mem.swp.t = math.floor(v/1024) |
| 42 |
elseif k == "SwapFree" then _mem.swp.f = math.floor(v/1024) |
| 43 |
end |
| 44 |
end |
| 45 |
end |
| 46 |
|
| 47 |
|
| 48 |
_mem.free = _mem.buf.a |
| 49 |
_mem.inuse = _mem.total - _mem.free |
| 50 |
_mem.bcuse = _mem.total - _mem.buf.f |
| 51 |
_mem.usep = math.floor(_mem.inuse / _mem.total * 100) |
| 52 |
|
| 53 |
_mem.swp.inuse = _mem.swp.t - _mem.swp.f |
| 54 |
_mem.swp.usep = math.floor(_mem.swp.inuse / _mem.swp.t * 100) |
| 55 |
|
| 56 |
return {_mem.usep, _mem.inuse, _mem.total, _mem.free, |
| 57 |
_mem.swp.usep, _mem.swp.inuse, _mem.swp.t, _mem.swp.f, |
| 58 |
_mem.bcuse } |
| 59 |
end) |
| 60 |
|