Merge pull request #56 from psycorama/master

FreeBSD memory widgets bugfixes and improvements
This commit is contained in:
mutlusun 2018-03-19 20:44:09 +01:00 committed by GitHub
commit d9287de8e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 36 deletions

View File

@ -323,9 +323,10 @@ 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 10th value as memory usage with buffers and cache * FreeBSD: see above, but there are four more values: the 9th value is wired memory
as percent and 11th value as wired memory (memory used by kernel) is in percent, the 10th value is wired memory. The 11th and 12th value return
reported 'not freeable memory' (basically active+inactive+wired) in percent and megabytes,
respectively.
**vicious.widgets.mpd** **vicious.widgets.mpd**
@ -805,8 +806,8 @@ Format functions can be used as well:
naughty.notify({ title = "Battery indicator", naughty.notify({ title = "Battery indicator",
text = vicious.call(vicious.widgets.bat, function(widget, args) text = vicious.call(vicious.widgets.bat, function(widget, args)
return string.format("%s: %10sh\n%s: %14d%%\n%s: %12dW", return string.format("%s: %10sh\n%s: %14d%%\n%s: %12dW",
"Remaining time", args[3], "Remaining time", args[3],
"Wear level", args[4], "Wear level", args[4],
"Present rate", args[5]) "Present rate", args[5])
end, "0") }) end, "0") })
end) end)

View File

@ -30,6 +30,8 @@ local function worker(format, warg)
state = "" state = ""
elseif bat_info["State"] == "charging" then elseif bat_info["State"] == "charging" then
state = "+" state = "+"
elseif bat_info["State"] == "critical charging" then
state = "+"
elseif bat_info["State"] == "discharging" then elseif bat_info["State"] == "discharging" then
state = "-" state = "-"
else else

View File

@ -16,55 +16,56 @@ local function worker(format)
local vm_stats = helpers.sysctl_table("vm.stats.vm") local vm_stats = helpers.sysctl_table("vm.stats.vm")
local _mem = { buf = {}, total = nil } local _mem = { buf = {}, total = nil }
-- 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/(1024*1024)) _mem.total = math.floor(_mem.total/1048576)
_mem.buf.f = math.floor(_mem.buf.f/(1024*1024)) _mem.buf.free = math.floor(_mem.buf.free/1048576)
_mem.buf.a = math.floor(_mem.buf.a/(1024*1024)) _mem.buf.laundry = math.floor(_mem.buf.laundry/1048576)
_mem.buf.i = math.floor(_mem.buf.i/(1024*1024)) _mem.buf.cache = math.floor(_mem.buf.cache/1048576)
_mem.buf.c = math.floor(_mem.buf.c/(1024*1024)) _mem.buf.wired = math.floor(_mem.buf.wired/1048576)
_mem.buf.w = math.floor(_mem.buf.w/(1024*1024))
-- Calculate memory percentage -- Calculate memory percentage
_mem.free = _mem.buf.f + _mem.buf.c _mem.free = _mem.buf.free + _mem.buf.cache
_mem.inuse = _mem.buf.a + _mem.buf.i -- used memory basically consists of active+inactive+wired
_mem.wire = _mem.buf.w _mem.inuse = _mem.total - _mem.free
_mem.bcuse = _mem.total - _mem.buf.f _mem.notfreeable = _mem.inuse - _mem.buf.laundry
_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)
_mem.buffp = math.floor(_mem.bcuse / _mem.total * 100) _mem.notfreeablep = math.floor(_mem.notfreeable / _mem.total * 100)
_mem.wirep = math.floor(_mem.wire / _mem.total * 100)
-- Get swap states -- Get swap states
local vm = helpers.sysctl_table("vm") local vm_swap_total = tonumber(helpers.sysctl("vm.swap_total"))
local vm_swap_enabled = tonumber(helpers.sysctl("vm.swap_enabled"))
local _swp = { buf = {}, total = nil } local _swp = { buf = {}, total = nil }
if tonumber(vm.swap_enabled) == 1 and tonumber(vm.swap_total) > 0 then if vm_swap_enabled == 1 and vm_swap_total > 0 then
-- Get swap space -- Get swap space in bytes
_swp.total = tonumber(vm.swap_total) _swp.total = vm_swap_total
_swp.buf.f = _swp.total - tonumber(vm_stats.v_swapin) _swp.buf.free = _swp.total - tonumber(vm_stats.v_swapin)
-- Rework into megabytes -- Rework into megabytes
_swp.total = math.floor(_swp.total/(1024*1024)) _swp.total = math.floor(_swp.total/1048576)
_swp.buf.f = math.floor(_swp.buf.f/(1024*1024)) _swp.buf.free = math.floor(_swp.buf.free/1048576)
-- Calculate percentage -- Calculate percentage
_swp.inuse = _swp.total - _swp.buf.f _swp.inuse = _swp.total - _swp.buf.free
_swp.usep = math.floor(_swp.inuse / _swp.total * 100) _swp.usep = math.floor(_swp.inuse / _swp.total * 100)
else else
_swp.usep = -1 _swp.usep = -1
_swp.inuse = -1 _swp.inuse = -1
_swp.total = -1 _swp.total = -1
_swp.buf.f = -1 _swp.buf.free = -1
end end
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.free,
_mem.bcuse, _mem.buffp, _mem.wirep } _mem.wirep, _mem.wire, _mem.notfreeablep, _mem.notfreeable }
end end
return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end }) return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })