Skip to content

Commit 18d9d3a

Browse files
author
mutlusun
committed
Merge remote-tracking branch 'upstream/master'
2 parents ebc3a08 + d9287de commit 18d9d3a

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ Supported platforms: Linux, FreeBSD.
323323
total system memory, 4th as free memory, 5th as swap usage in percent, 6th
324324
as swap usage, 7th as total system swap, 8th as free swap and 9th as
325325
memory usage with buffers and cache
326-
* FreeBSD: see above, but 9th value is not returned (always `-1`) and there
327-
is a 10th value giving wired memory
326+
* FreeBSD: see above, but there are four more values: the 9th value is wired memory
327+
in percent, the 10th value is wired memory. The 11th and 12th value return
328+
'not freeable memory' (basically active+inactive+wired) in percent and megabytes,
329+
respectively.
328330

329331
**vicious.widgets.mpd**
330332

@@ -804,8 +806,8 @@ Format functions can be used as well:
804806
naughty.notify({ title = "Battery indicator",
805807
text = vicious.call(vicious.widgets.bat, function(widget, args)
806808
return string.format("%s: %10sh\n%s: %14d%%\n%s: %12dW",
807-
"Remaining time", args[3],
808-
"Wear level", args[4],
809+
"Remaining time", args[3],
810+
"Wear level", args[4],
809811
"Present rate", args[5])
810812
end, "0") })
811813
end)

widgets/mem_freebsd.lua

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,54 @@ local function worker(format)
1818

1919
-- Get memory space in bytes
2020
_mem.total = tonumber(vm_stats.v_page_count) * pagesize
21-
_mem.buf.f = tonumber(vm_stats.v_free_count) * pagesize
22-
_mem.buf.a = tonumber(vm_stats.v_active_count) * pagesize
23-
_mem.buf.i = tonumber(vm_stats.v_inactive_count) * pagesize
24-
_mem.buf.c = tonumber(vm_stats.v_cache_count) * pagesize
25-
_mem.buf.w = tonumber(vm_stats.v_wire_count) * pagesize
21+
_mem.buf.free = tonumber(vm_stats.v_free_count) * pagesize
22+
_mem.buf.laundry = tonumber(vm_stats.v_laundry_count) * pagesize
23+
_mem.buf.cache = tonumber(vm_stats.v_cache_count) * pagesize
24+
_mem.buf.wired = tonumber(vm_stats.v_wire_count) * pagesize
2625

2726
-- Rework into megabytes
2827
_mem.total = math.floor(_mem.total/1048576)
29-
_mem.buf.f = math.floor(_mem.buf.f/1048576)
30-
_mem.buf.a = math.floor(_mem.buf.a/1048576)
31-
_mem.buf.i = math.floor(_mem.buf.i/1048576)
32-
_mem.buf.c = math.floor(_mem.buf.c/1048576)
33-
_mem.buf.w = math.floor(_mem.buf.w/1048576)
28+
_mem.buf.free = math.floor(_mem.buf.free/1048576)
29+
_mem.buf.laundry = math.floor(_mem.buf.laundry/1048576)
30+
_mem.buf.cache = math.floor(_mem.buf.cache/1048576)
31+
_mem.buf.wired = math.floor(_mem.buf.wired/1048576)
3432

3533
-- Calculate memory percentage
36-
_mem.free = _mem.buf.f + _mem.buf.c + _mem.buf.i
34+
_mem.free = _mem.buf.free + _mem.buf.cache
35+
-- used memory basically consists of active+inactive+wired
3736
_mem.inuse = _mem.total - _mem.free
38-
_mem.wire = _mem.buf.w
37+
_mem.notfreeable = _mem.inuse - _mem.buf.laundry
38+
_mem.wire = _mem.buf.wired
39+
3940
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
40-
_mem.inusep= math.floor(_mem.inuse / _mem.total * 100)
41+
_mem.wirep = math.floor(_mem.wire / _mem.total * 100)
42+
_mem.notfreeablep = math.floor(_mem.notfreeable / _mem.total * 100)
4143

4244
-- Get swap states
4345
local vm_swap_total = tonumber(helpers.sysctl("vm.swap_total"))
4446
local vm_swap_enabled = tonumber(helpers.sysctl("vm.swap_enabled"))
4547
local _swp = { buf = {}, total = nil }
46-
48+
4749
if vm_swap_enabled == 1 and vm_swap_total > 0 then
4850
-- Get swap space in bytes
4951
_swp.total = vm_swap_total
50-
_swp.buf.f = _swp.total - tonumber(vm_stats.v_swapin)
52+
_swp.buf.free = _swp.total - tonumber(vm_stats.v_swapin)
5153
-- Rework into megabytes
5254
_swp.total = math.floor(_swp.total/1048576)
53-
_swp.buf.f = math.floor(_swp.buf.f/1048576)
55+
_swp.buf.free = math.floor(_swp.buf.free/1048576)
5456
-- Calculate percentage
55-
_swp.inuse = _swp.total - _swp.buf.f
57+
_swp.inuse = _swp.total - _swp.buf.free
5658
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
5759
else
5860
_swp.usep = -1
5961
_swp.inuse = -1
6062
_swp.total = -1
61-
_swp.buf.f = -1
63+
_swp.buf.free = -1
6264
end
6365

6466
return { _mem.usep, _mem.inuse, _mem.total, _mem.free,
65-
_swp.usep, _swp.inuse, _swp.total, _swp.buf.f,
66-
-1, _mem.wire }
67+
_swp.usep, _swp.inuse, _swp.total, _swp.buf.free,
68+
_mem.wirep, _mem.wire, _mem.notfreeablep, _mem.notfreeable }
6769
end
6870

6971
return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })

0 commit comments

Comments
 (0)