@@ -16,42 +16,41 @@ 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
2021 _mem .buf .f = tonumber (vm_stats .v_free_count ) * pagesize
2122 _mem .buf .a = tonumber (vm_stats .v_active_count ) * pagesize
2223 _mem .buf .i = tonumber (vm_stats .v_inactive_count ) * pagesize
2324 _mem .buf .c = tonumber (vm_stats .v_cache_count ) * pagesize
2425 _mem .buf .w = tonumber (vm_stats .v_wire_count ) * pagesize
2526
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 ) )
27+ -- Rework into megabytes
28+ _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 )
3334
3435 -- Calculate memory percentage
35- _mem .free = _mem .buf .f + _mem .buf .c
36- _mem .inuse = _mem .buf . a + _mem .buf . i
36+ _mem .free = _mem .buf .f + _mem .buf .c + _mem . buf . i
37+ _mem .inuse = _mem .total - _mem .free
3738 _mem .wire = _mem .buf .w
38- _mem .bcuse = _mem .total - _mem .buf .f
3939 _mem .usep = math.floor (_mem .inuse / _mem .total * 100 )
4040 _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 )
4341
4442 -- Get swap states
45- local vm = helpers .sysctl_table (" vm" )
43+ local vm_swap_total = tonumber (helpers .sysctl (" vm.swap_total" ))
44+ local vm_swap_enabled = tonumber (helpers .sysctl (" vm.swap_enabled" ))
4645 local _swp = { buf = {}, total = nil }
4746
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 )
47+ if vm_swap_enabled == 1 and vm_swap_total > 0 then
48+ -- Get swap space in bytes
49+ _swp .total = vm_swap_total
5150 _swp .buf .f = _swp .total - tonumber (vm_stats .v_swapin )
5251 -- Rework into megabytes
53- _swp .total = math.floor (_swp .total / ( 1024 * 1024 ) )
54- _swp .buf .f = math.floor (_swp .buf .f / ( 1024 * 1024 ) )
52+ _swp .total = math.floor (_swp .total / 1048576 )
53+ _swp .buf .f = math.floor (_swp .buf .f / 1048576 )
5554 -- Calculate percentage
5655 _swp .inuse = _swp .total - _swp .buf .f
5756 _swp .usep = math.floor (_swp .inuse / _swp .total * 100 )
@@ -64,7 +63,7 @@ local function worker(format)
6463
6564 return { _mem .usep , _mem .inuse , _mem .total , _mem .free ,
6665 _swp .usep , _swp .inuse , _swp .total , _swp .buf .f ,
67- _mem . bcuse , _mem .buffp , _mem . wirep }
66+ - 1 , _mem .wire }
6867end
6968
7069return setmetatable (mem_freebsd , { __call = function (_ , ...) return worker (... ) end })
0 commit comments