ADD config option for swap
This commit is contained in:
parent
6a022c36c6
commit
eb32a6a391
|
@ -16,6 +16,7 @@ modules:
|
||||||
show_vid_util: true
|
show_vid_util: true
|
||||||
memory:
|
memory:
|
||||||
show_stats: true
|
show_stats: true
|
||||||
|
show_swap: false
|
||||||
show_plot: true
|
show_plot: true
|
||||||
table_rows: 5
|
table_rows: 5
|
||||||
power:
|
power:
|
||||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 87f03c704fe2899d5e780255ac1634d8c260c8fe
|
Subproject commit aa0d02748b4316c44e21cc4af24727aba82159ff
|
|
@ -2,6 +2,7 @@ local timeseries = require 'timeseries'
|
||||||
local text_table = require 'text_table'
|
local text_table = require 'text_table'
|
||||||
local i_o = require 'i_o'
|
local i_o = require 'i_o'
|
||||||
local pure = require 'pure'
|
local pure = require 'pure'
|
||||||
|
local sys = require 'sys'
|
||||||
|
|
||||||
return function(update_freq, config, common, width, point)
|
return function(update_freq, config, common, width, point)
|
||||||
local DIAL_THICKNESS = 8
|
local DIAL_THICKNESS = 8
|
||||||
|
@ -14,39 +15,25 @@ return function(update_freq, config, common, width, point)
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
local TABLE_SECTION_BREAK = 20
|
local TABLE_SECTION_BREAK = 20
|
||||||
|
|
||||||
local __string_match = string.match
|
|
||||||
local __math_floor = math.floor
|
local __math_floor = math.floor
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- state
|
-- state
|
||||||
|
|
||||||
local use_swap = false
|
local mod_state = {mem = {total = sys.meminfo_field_reader('MemTotal')()}}
|
||||||
|
local update_state
|
||||||
|
|
||||||
local MEMINFO_REGEX = '\nMemFree:%s+(%d+).+'..
|
if config.show_swap == true then
|
||||||
'\nBuffers:%s+(%d+).+'..
|
mod_state.swap = {total = sys.meminfo_field_reader('SwapTotal')()}
|
||||||
'\nCached:%s+(%d+).+'..
|
update_state = sys.meminfo_updater_swap(mod_state.mem, mod_state.swap)
|
||||||
'\nSwapFree:%s+(%d+).+'..
|
else
|
||||||
'\nShmem:%s+(%d+).+'..
|
update_state = sys.meminfo_updater_noswap(mod_state.mem)
|
||||||
'\nSReclaimable:%s+(%d+)'
|
|
||||||
|
|
||||||
local get_meminfo_field = function(field)
|
|
||||||
return tonumber(i_o.read_file('/proc/meminfo', field..':%s+(%d+)'))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local mod_state = {
|
|
||||||
mem = {total = get_meminfo_field('MemTotal')},
|
|
||||||
swap = {total = get_meminfo_field('SwapTotal')}
|
|
||||||
}
|
|
||||||
local read_state = function()
|
local read_state = function()
|
||||||
local m = mod_state.mem
|
update_state()
|
||||||
-- see manpage for free command for formulas
|
-- see manpage for free command for formulas
|
||||||
m.memfree,
|
local m = mod_state.mem
|
||||||
m.buffers,
|
|
||||||
m.cached,
|
|
||||||
mod_state.swap.free,
|
|
||||||
m.shmem,
|
|
||||||
m.sreclaimable
|
|
||||||
= __string_match(i_o.read_file('/proc/meminfo'), MEMINFO_REGEX)
|
|
||||||
m.used_percent =
|
m.used_percent =
|
||||||
(m.total -
|
(m.total -
|
||||||
m.memfree -
|
m.memfree -
|
||||||
|
@ -55,7 +42,6 @@ return function(update_freq, config, common, width, point)
|
||||||
m.sreclaimable) / m.total
|
m.sreclaimable) / m.total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- mem stats (dial + text)
|
-- mem stats (dial + text)
|
||||||
|
|
||||||
|
@ -64,7 +50,7 @@ return function(update_freq, config, common, width, point)
|
||||||
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
|
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
|
||||||
local CACHE_X
|
local CACHE_X
|
||||||
local SWAP_X
|
local SWAP_X
|
||||||
if use_swap == true then
|
if config.show_swap == true then
|
||||||
SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING
|
SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING
|
||||||
CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
|
CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
|
||||||
else
|
else
|
||||||
|
@ -114,7 +100,7 @@ return function(update_freq, config, common, width, point)
|
||||||
local ret = pure.partial(common.mk_acc, width, DIAL_DIAMETER)
|
local ret = pure.partial(common.mk_acc, width, DIAL_DIAMETER)
|
||||||
|
|
||||||
-- add swap bits if needed
|
-- add swap bits if needed
|
||||||
if use_swap == true then
|
if config.show_swap == true then
|
||||||
local swap = common.make_dial(
|
local swap = common.make_dial(
|
||||||
SWAP_X,
|
SWAP_X,
|
||||||
y + DIAL_RADIUS,
|
y + DIAL_RADIUS,
|
||||||
|
|
|
@ -55,6 +55,9 @@ properties:
|
||||||
show_stats:
|
show_stats:
|
||||||
description: show memory stats/dial
|
description: show memory stats/dial
|
||||||
type: boolean
|
type: boolean
|
||||||
|
show_swap:
|
||||||
|
description: show swap dial
|
||||||
|
type: boolean
|
||||||
show_plot:
|
show_plot:
|
||||||
description: show the RAM utilization plot
|
description: show the RAM utilization plot
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|
Loading…
Reference in New Issue