@@ -16,55 +16,56 @@ local function worker(format)
1616 local vm_stats = helpers .sysctl_table (" vm.stats.vm" )
1717 local _mem = { buf = {}, total = nil }
1818
19+ -- Get memory space in bytes
1920 _mem .total = tonumber (vm_stats .v_page_count ) * pagesize
20- _mem .buf .f = tonumber (vm_stats .v_free_count ) * pagesize
21- _mem .buf .a = tonumber (vm_stats .v_active_count ) * pagesize
22- _mem .buf .i = tonumber (vm_stats .v_inactive_count ) * pagesize
23- _mem .buf .c = tonumber (vm_stats .v_cache_count ) * pagesize
24- _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
2525
26- -- rework into Megabytes
27- _mem .total = math.floor (_mem .total / (1024 * 1024 ))
28- _mem .buf .f = math.floor (_mem .buf .f / (1024 * 1024 ))
29- _mem .buf .a = math.floor (_mem .buf .a / (1024 * 1024 ))
30- _mem .buf .i = math.floor (_mem .buf .i / (1024 * 1024 ))
31- _mem .buf .c = math.floor (_mem .buf .c / (1024 * 1024 ))
32- _mem .buf .w = math.floor (_mem .buf .w / (1024 * 1024 ))
26+ -- Rework into megabytes
27+ _mem .total = math.floor (_mem .total / 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 )
3332
3433 -- Calculate memory percentage
35- _mem .free = _mem .buf .f + _mem .buf .c
36- _mem .inuse = _mem .buf .a + _mem .buf .i
37- _mem .wire = _mem .buf .w
38- _mem .bcuse = _mem .total - _mem .buf .f
34+ _mem .free = _mem .buf .free + _mem .buf .cache
35+ -- used memory basically consists of active+inactive+wired
36+ _mem .inuse = _mem .total - _mem .free
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 .buffp = math.floor (_mem .bcuse / _mem .total * 100 )
42- _mem .wirep = math.floor (_mem .wire / _mem .total * 100 )
41+ _mem .wirep = math.floor (_mem .wire / _mem .total * 100 )
42+ _mem .notfreeablep = math.floor (_mem .notfreeable / _mem .total * 100 )
4343
4444 -- Get swap states
45- local vm = helpers .sysctl_table (" vm" )
45+ local vm_swap_total = tonumber (helpers .sysctl (" vm.swap_total" ))
46+ local vm_swap_enabled = tonumber (helpers .sysctl (" vm.swap_enabled" ))
4647 local _swp = { buf = {}, total = nil }
47-
48- if tonumber ( vm . swap_enabled ) == 1 and tonumber ( vm . swap_total ) > 0 then
49- -- Get swap space
50- _swp .total = tonumber ( vm . swap_total )
51- _swp .buf .f = _swp .total - tonumber (vm_stats .v_swapin )
48+
49+ if vm_swap_enabled == 1 and vm_swap_total > 0 then
50+ -- Get swap space in bytes
51+ _swp .total = vm_swap_total
52+ _swp .buf .free = _swp .total - tonumber (vm_stats .v_swapin )
5253 -- Rework into megabytes
53- _swp .total = math.floor (_swp .total / ( 1024 * 1024 ) )
54- _swp .buf .f = math.floor (_swp .buf .f / ( 1024 * 1024 ) )
54+ _swp .total = math.floor (_swp .total / 1048576 )
55+ _swp .buf .free = math.floor (_swp .buf .free / 1048576 )
5556 -- Calculate percentage
56- _swp .inuse = _swp .total - _swp .buf .f
57+ _swp .inuse = _swp .total - _swp .buf .free
5758 _swp .usep = math.floor (_swp .inuse / _swp .total * 100 )
5859 else
5960 _swp .usep = - 1
6061 _swp .inuse = - 1
6162 _swp .total = - 1
62- _swp .buf .f = - 1
63+ _swp .buf .free = - 1
6364 end
6465
6566 return { _mem .usep , _mem .inuse , _mem .total , _mem .free ,
66- _swp .usep , _swp .inuse , _swp .total , _swp .buf .f ,
67- _mem .bcuse , _mem .buffp , _mem .wirep }
67+ _swp .usep , _swp .inuse , _swp .total , _swp .buf .free ,
68+ _mem .wirep , _mem .wire , _mem .notfreeablep , _mem . notfreeable }
6869end
6970
7071return setmetatable (mem_freebsd , { __call = function (_ , ...) return worker (... ) end })
0 commit comments