memory freebsd: re-organizes memory assignment for used and unused memory
* removes unused variables * enhances one-character-variables for better readabilitiy * fixes calculation errors ** used memory: active, inactive, and wired ** available memory: cached, laundry, and free see https://wiki.freebsd.org/Memory for more information
This commit is contained in:
parent
0280ac2243
commit
df5fa77428
|
@ -323,8 +323,8 @@ Supported platforms: Linux, FreeBSD.
|
||||||
total system memory, 4th as free memory, 5th as swap usage in percent, 6th
|
total system memory, 4th as free memory, 5th as swap usage in percent, 6th
|
||||||
as swap usage, 7th as total system swap, 8th as free swap and 9th as
|
as swap usage, 7th as total system swap, 8th as free swap and 9th as
|
||||||
memory usage with buffers and cache
|
memory usage with buffers and cache
|
||||||
* FreeBSD: see above, but 9th value is not returned (always `-1`) and there
|
* FreeBSD: see above, but there are two more values: the 9th value is wired memory
|
||||||
is a 10th value giving wired memory
|
in percent and the 10th value giving wired memory
|
||||||
|
|
||||||
**vicious.widgets.mpd**
|
**vicious.widgets.mpd**
|
||||||
|
|
||||||
|
|
|
@ -18,26 +18,25 @@ local function worker(format)
|
||||||
|
|
||||||
-- Get memory space in bytes
|
-- Get memory space in bytes
|
||||||
_mem.total = tonumber(vm_stats.v_page_count) * pagesize
|
_mem.total = tonumber(vm_stats.v_page_count) * pagesize
|
||||||
_mem.buf.f = tonumber(vm_stats.v_free_count) * pagesize
|
_mem.buf.free = tonumber(vm_stats.v_free_count) * pagesize
|
||||||
_mem.buf.a = tonumber(vm_stats.v_active_count) * pagesize
|
_mem.buf.laundry = tonumber(vm_stats.v_laundry_count) * pagesize
|
||||||
_mem.buf.i = tonumber(vm_stats.v_inactive_count) * pagesize
|
_mem.buf.cache = tonumber(vm_stats.v_cache_count) * pagesize
|
||||||
_mem.buf.c = tonumber(vm_stats.v_cache_count) * pagesize
|
_mem.buf.wired = tonumber(vm_stats.v_wire_count) * pagesize
|
||||||
_mem.buf.w = tonumber(vm_stats.v_wire_count) * pagesize
|
|
||||||
|
|
||||||
-- Rework into megabytes
|
-- Rework into megabytes
|
||||||
_mem.total = math.floor(_mem.total/1048576)
|
_mem.total = math.floor(_mem.total/1048576)
|
||||||
_mem.buf.f = math.floor(_mem.buf.f/1048576)
|
_mem.buf.free = math.floor(_mem.buf.free/1048576)
|
||||||
_mem.buf.a = math.floor(_mem.buf.a/1048576)
|
_mem.buf.laundry = math.floor(_mem.buf.laundry/1048576)
|
||||||
_mem.buf.i = math.floor(_mem.buf.i/1048576)
|
_mem.buf.cache = math.floor(_mem.buf.cache/1048576)
|
||||||
_mem.buf.c = math.floor(_mem.buf.c/1048576)
|
_mem.buf.wired = math.floor(_mem.buf.wired/1048576)
|
||||||
_mem.buf.w = math.floor(_mem.buf.w/1048576)
|
|
||||||
|
|
||||||
-- Calculate memory percentage
|
-- Calculate memory percentage
|
||||||
_mem.free = _mem.buf.f + _mem.buf.c + _mem.buf.i
|
_mem.free = _mem.buf.free + _mem.buf.cache + _mem.buf.laundry
|
||||||
|
-- used memory basically consists of active+inactive+wired
|
||||||
_mem.inuse = _mem.total - _mem.free
|
_mem.inuse = _mem.total - _mem.free
|
||||||
_mem.wire = _mem.buf.w
|
_mem.wire = _mem.buf.wired
|
||||||
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
|
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
|
||||||
_mem.inusep= math.floor(_mem.inuse / _mem.total * 100)
|
_mem.wirep = math.floor(_mem.wire / _mem.total * 100)
|
||||||
|
|
||||||
-- Get swap states
|
-- Get swap states
|
||||||
local vm_swap_total = tonumber(helpers.sysctl("vm.swap_total"))
|
local vm_swap_total = tonumber(helpers.sysctl("vm.swap_total"))
|
||||||
|
@ -63,7 +62,7 @@ local function worker(format)
|
||||||
|
|
||||||
return { _mem.usep, _mem.inuse, _mem.total, _mem.free,
|
return { _mem.usep, _mem.inuse, _mem.total, _mem.free,
|
||||||
_swp.usep, _swp.inuse, _swp.total, _swp.buf.f,
|
_swp.usep, _swp.inuse, _swp.total, _swp.buf.f,
|
||||||
-1, _mem.wire }
|
_mem.wirep, _mem.wire }
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
Loading…
Reference in New Issue