2021-07-17 23:45:12 -04:00
|
|
|
local Arc = require 'Arc'
|
|
|
|
local Dial = require 'Dial'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
|
|
|
local Table = require 'Table'
|
|
|
|
local Util = require 'Util'
|
|
|
|
local Common = require 'Common'
|
2021-07-16 23:25:44 -04:00
|
|
|
local Theme = require 'Patterns'
|
|
|
|
local Geometry = require 'Geometry'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
return function(update_freq)
|
|
|
|
local MODULE_Y = 712
|
|
|
|
local DIAL_THICKNESS = 8
|
|
|
|
local TEXT_Y_OFFSET = 7
|
|
|
|
local TEXT_LEFT_X_OFFSET = 30
|
|
|
|
local TEXT_SPACING = 20
|
|
|
|
local PLOT_SECTION_BREAK = 30
|
|
|
|
local PLOT_HEIGHT = 56
|
|
|
|
local TABLE_SECTION_BREAK = 20
|
|
|
|
local TABLE_HEIGHT = 114
|
|
|
|
|
|
|
|
local MEMINFO_REGEX = '\nMemFree:%s+(%d+).+'..
|
|
|
|
'\nBuffers:%s+(%d+).+'..
|
|
|
|
'\nCached:%s+(%d+).+'..
|
|
|
|
'\nSwapTotal:%s+(%d+).+'..
|
|
|
|
'\nSwapFree:%s+(%d+).+'..
|
|
|
|
'\nSReclaimable:%s+(%d+)'
|
|
|
|
|
|
|
|
local __string_match = string.match
|
|
|
|
local __cairo_path_destroy = cairo_path_destroy
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- header
|
|
|
|
|
|
|
|
local header = Common.Header(
|
|
|
|
Geometry.RIGHT_X,
|
|
|
|
MODULE_Y,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
'MEMORY'
|
|
|
|
)
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- mem consumption dial
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
local mem_total_kb = tonumber(Util.read_file('/proc/meminfo', '^MemTotal:%s+(%d+)'))
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
local DIAL_RADIUS = 32
|
2021-07-18 14:38:41 -04:00
|
|
|
-- local DIAL_THETA_0 = math.rad(90)
|
|
|
|
-- local DIAL_THETA_1 = math.rad(360)
|
2021-07-17 23:45:12 -04:00
|
|
|
local DIAL_X = Geometry.RIGHT_X + DIAL_RADIUS + DIAL_THICKNESS / 2
|
|
|
|
local DIAL_Y = header.bottom_y + DIAL_RADIUS + DIAL_THICKNESS / 2
|
|
|
|
|
|
|
|
local dial = Common.dial(DIAL_X, DIAL_Y, DIAL_RADIUS, DIAL_THICKNESS, 0.8)
|
2021-07-18 14:38:41 -04:00
|
|
|
-- local cache_arc = Common.arc(
|
|
|
|
-- DIAL_X,
|
|
|
|
-- DIAL_Y,
|
|
|
|
-- DIAL_RADIUS,
|
|
|
|
-- DIAL_THICKNESS,
|
|
|
|
-- Theme.INDICATOR_FG_SECONDARY
|
|
|
|
-- )
|
2021-07-17 23:45:12 -04:00
|
|
|
local text_ring = Common.initTextRing(
|
|
|
|
DIAL_X,
|
|
|
|
DIAL_Y,
|
|
|
|
DIAL_RADIUS - DIAL_THICKNESS / 2 - 2,
|
|
|
|
'%s%%',
|
|
|
|
80
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- swap/buffers stats
|
|
|
|
|
|
|
|
local LINE_1_Y = header.bottom_y + TEXT_Y_OFFSET
|
|
|
|
local TEXT_LEFT_X = Geometry.RIGHT_X + DIAL_RADIUS * 2 + TEXT_LEFT_X_OFFSET
|
|
|
|
local SWAP_BUFFERS_WIDTH = Geometry.SECTION_WIDTH - TEXT_LEFT_X_OFFSET
|
|
|
|
- DIAL_RADIUS * 2
|
|
|
|
|
|
|
|
local swap = Common.initTextRowCrit(
|
|
|
|
TEXT_LEFT_X,
|
|
|
|
LINE_1_Y,
|
|
|
|
SWAP_BUFFERS_WIDTH,
|
|
|
|
'Swap Usage',
|
|
|
|
'%s%%',
|
|
|
|
80
|
|
|
|
)
|
|
|
|
|
2021-07-18 14:38:41 -04:00
|
|
|
-- local cache = Common.initTextRows_color(
|
|
|
|
local cache = Common.initTextRows_formatted(
|
2021-07-17 23:45:12 -04:00
|
|
|
TEXT_LEFT_X,
|
|
|
|
LINE_1_Y + TEXT_SPACING,
|
|
|
|
SWAP_BUFFERS_WIDTH,
|
|
|
|
TEXT_SPACING,
|
|
|
|
{'Page Cache', 'Buffers', 'Kernel Slab'},
|
2021-07-18 14:38:41 -04:00
|
|
|
-- Theme.SECONDARY_FG,
|
2021-07-17 23:45:12 -04:00
|
|
|
'%s%%'
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- memory consumption plot
|
|
|
|
|
|
|
|
local PLOT_Y = PLOT_SECTION_BREAK + header.bottom_y + DIAL_RADIUS * 2
|
2021-07-17 16:43:00 -04:00
|
|
|
|
|
|
|
local plot = Common.initThemedLabelPlot(
|
|
|
|
Geometry.RIGHT_X,
|
2021-07-17 23:45:12 -04:00
|
|
|
PLOT_Y,
|
2021-07-17 16:43:00 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-17 23:45:12 -04:00
|
|
|
PLOT_HEIGHT,
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.percent_label_style,
|
|
|
|
update_freq
|
|
|
|
)
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- memory top table
|
|
|
|
|
|
|
|
local NUM_ROWS = 5
|
|
|
|
local TABLE_CONKY = {}
|
|
|
|
for r = 1, NUM_ROWS do
|
|
|
|
TABLE_CONKY[r] = {
|
|
|
|
comm = '${top_mem name '..r..'}',
|
|
|
|
pid = '${top_mem pid '..r..'}',
|
|
|
|
mem = '${top_mem mem '..r..'}',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local tbl = Common.initTable(
|
|
|
|
Geometry.RIGHT_X,
|
|
|
|
PLOT_Y + PLOT_HEIGHT + TABLE_SECTION_BREAK,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
TABLE_HEIGHT,
|
|
|
|
NUM_ROWS,
|
|
|
|
{'Name', 'PID', 'Mem (%)'}
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- main functions
|
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local update = function(cr)
|
|
|
|
local conky = Util.conky
|
|
|
|
-- see source for the 'free' command (sysinfo.c) for formulas
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
local memfree_kb,
|
|
|
|
buffers_kb,
|
|
|
|
cached_kb,
|
|
|
|
swap_total_kb,
|
|
|
|
swap_free_kb,
|
|
|
|
slab_reclaimable_kb
|
|
|
|
= __string_match(Util.read_file('/proc/meminfo'), MEMINFO_REGEX)
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 23:45:12 -04:00
|
|
|
local used_percent = (mem_total_kb - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / mem_total_kb
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Dial.set(dial, used_percent)
|
|
|
|
Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100))
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-18 14:38:41 -04:00
|
|
|
-- local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / mem_total_kb * memfree_kb + DIAL_THETA_1
|
|
|
|
-- __cairo_path_destroy(cache_arc.path)
|
|
|
|
-- cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta)
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_row_crit_set(swap, cr,
|
|
|
|
Util.precision_round_to_string(
|
|
|
|
(swap_total_kb - swap_free_kb)
|
|
|
|
/ swap_total_kb * 100))
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_rows_set(cache, cr, 1, Util.precision_round_to_string(
|
2021-07-17 23:45:12 -04:00
|
|
|
cached_kb / mem_total_kb * 100))
|
2020-04-11 15:14:14 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_rows_set(cache, cr, 2, Util.precision_round_to_string(
|
2021-07-17 23:45:12 -04:00
|
|
|
buffers_kb / mem_total_kb * 100))
|
2021-07-17 16:43:00 -04:00
|
|
|
|
|
|
|
Common.text_rows_set(cache, cr, 3, Util.precision_round_to_string(
|
2021-07-17 23:45:12 -04:00
|
|
|
slab_reclaimable_kb / mem_total_kb * 100))
|
2021-07-17 16:43:00 -04:00
|
|
|
|
|
|
|
LabelPlot.update(plot, used_percent)
|
|
|
|
|
|
|
|
for r = 1, NUM_ROWS do
|
2021-07-17 23:45:12 -04:00
|
|
|
Table.set(tbl, cr, 1, r, conky(TABLE_CONKY[r].comm, '(%S+)'))
|
|
|
|
Table.set(tbl, cr, 2, r, conky(TABLE_CONKY[r].pid))
|
|
|
|
Table.set(tbl, cr, 3, r, conky(TABLE_CONKY[r].mem))
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
2020-04-11 15:14:14 -04:00
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local draw_static = function(cr)
|
|
|
|
Common.drawHeader(cr, header)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_ring_draw_static(text_ring, cr)
|
|
|
|
Dial.draw_static(dial, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_row_crit_draw_static(swap, cr)
|
|
|
|
Common.text_rows_draw_static(cache, cr)
|
|
|
|
LabelPlot.draw_static(plot, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Table.draw_static(tbl, cr)
|
|
|
|
end
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local draw_dynamic = function(cr)
|
|
|
|
update(cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Dial.draw_dynamic(dial, cr)
|
2021-07-18 14:38:41 -04:00
|
|
|
-- Arc.draw(cache_arc, cr)
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_ring_draw_dynamic(text_ring, cr)
|
|
|
|
|
|
|
|
Common.text_row_crit_draw_dynamic(swap, cr)
|
|
|
|
Common.text_rows_draw_dynamic(cache, cr)
|
|
|
|
|
|
|
|
LabelPlot.draw_dynamic(plot, cr)
|
|
|
|
|
|
|
|
Table.draw_dynamic(tbl, cr)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 00:17:22 -04:00
|
|
|
return {dynamic = draw_dynamic, static = draw_static}
|
|
|
|
end
|