2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local Arc = require 'Arc'
|
|
|
|
local Dial = require 'Dial'
|
|
|
|
local TextColumn = require 'TextColumn'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
|
|
|
local Table = require 'Table'
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
local Common = require 'Common'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local __string_match = string.match
|
|
|
|
local __cairo_path_destroy = cairo_path_destroy
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local MEM_TOTAL_KB = tonumber(Util.read_file('/proc/meminfo', '^MemTotal:%s+(%d+)'))
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local MEMINFO_REGEX = '\nMemFree:%s+(%d+).+'..
|
|
|
|
'\nBuffers:%s+(%d+).+'..
|
|
|
|
'\nCached:%s+(%d+).+'..
|
|
|
|
'\nSwapTotal:%s+(%d+).+'..
|
|
|
|
'\nSwapFree:%s+(%d+).+'..
|
|
|
|
'\nSReclaimable:%s+(%d+)'
|
|
|
|
|
|
|
|
local NUM_ROWS = 5
|
|
|
|
|
2020-04-11 15:14:14 -04:00
|
|
|
local TABLE_CONKY = {}
|
|
|
|
|
|
|
|
for r = 1, NUM_ROWS do
|
|
|
|
TABLE_CONKY[r] = {}
|
|
|
|
TABLE_CONKY[r].comm = '${top_mem name '..r..'}'
|
|
|
|
TABLE_CONKY[r].pid = '${top_mem pid '..r..'}'
|
|
|
|
TABLE_CONKY[r].mem = '${top_mem mem '..r..'}'
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local header = Common.Header(
|
|
|
|
_G_INIT_DATA_.RIGHT_X,
|
|
|
|
_MODULE_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
'MEMORY'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local DIAL_RADIUS = 32
|
|
|
|
local DIAL_THETA_0 = math.rad(90)
|
|
|
|
local DIAL_THETA_1 = math.rad(360)
|
|
|
|
local DIAL_X = _G_INIT_DATA_.RIGHT_X + DIAL_RADIUS + _DIAL_THICKNESS_ / 2
|
|
|
|
local DIAL_Y = header.bottom_y + DIAL_RADIUS + _DIAL_THICKNESS_ / 2
|
|
|
|
|
2021-07-08 22:57:35 -04:00
|
|
|
local dial = _G_Widget_.Dial(
|
2021-07-09 23:19:26 -04:00
|
|
|
_G_Widget_.make_semicircle(
|
|
|
|
_G_Widget_.make_point(DIAL_X, DIAL_Y),
|
|
|
|
DIAL_RADIUS,
|
|
|
|
90,
|
|
|
|
360
|
|
|
|
),
|
2021-07-10 14:43:20 -04:00
|
|
|
_G_Widget_.arc_style(
|
|
|
|
_DIAL_THICKNESS_,
|
|
|
|
_G_Patterns_.INDICATOR_BG
|
|
|
|
),
|
2021-07-10 23:33:25 -04:00
|
|
|
_G_Widget_.threshold_style(
|
|
|
|
_G_Patterns_.INDICATOR_FG_PRIMARY,
|
|
|
|
_G_Patterns_.INDICATOR_FG_CRITICAL,
|
|
|
|
0.8
|
|
|
|
)
|
2021-07-08 22:57:35 -04:00
|
|
|
)
|
|
|
|
local cache_arc = _G_Widget_.Arc(
|
2021-07-09 22:53:03 -04:00
|
|
|
_G_Widget_.make_semicircle(
|
|
|
|
_G_Widget_.make_point(DIAL_X, DIAL_Y),
|
|
|
|
DIAL_RADIUS,
|
|
|
|
90,
|
|
|
|
360
|
|
|
|
),
|
2021-07-10 14:43:20 -04:00
|
|
|
_G_Widget_.arc_style(
|
|
|
|
_DIAL_THICKNESS_,
|
|
|
|
_G_Patterns_.INDICATOR_FG_SECONDARY
|
|
|
|
)
|
2021-07-08 22:57:35 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local text_ring = Common.initTextRing(
|
|
|
|
DIAL_X,
|
|
|
|
DIAL_Y,
|
|
|
|
DIAL_RADIUS - _DIAL_THICKNESS_ / 2 - 2,
|
2021-07-10 19:07:45 -04:00
|
|
|
'%s%%',
|
2021-07-06 19:32:18 -04:00
|
|
|
80
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _LINE_1_Y_ = header.bottom_y + _TEXT_Y_OFFSET_
|
|
|
|
local _TEXT_LEFT_X_ = _G_INIT_DATA_.RIGHT_X + DIAL_RADIUS * 2 + _TEXT_LEFT_X_OFFSET_
|
|
|
|
local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local swap = Common.initTextRowCrit(
|
|
|
|
_TEXT_LEFT_X_,
|
|
|
|
_LINE_1_Y_,
|
|
|
|
-- TODO this is silly
|
|
|
|
_RIGHT_X_ - _TEXT_LEFT_X_,
|
|
|
|
'Swap Usage',
|
2021-07-10 19:07:45 -04:00
|
|
|
'%s%%',
|
2021-07-06 19:32:18 -04:00
|
|
|
80
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-09 22:22:49 -04:00
|
|
|
-- local cache = {
|
|
|
|
-- labels = _G_Widget_.TextColumn{
|
|
|
|
-- x = _TEXT_LEFT_X_,
|
|
|
|
-- y = _LINE_1_Y_ + _TEXT_SPACING_,
|
|
|
|
-- spacing = _TEXT_SPACING_,
|
|
|
|
-- text_color = _G_Patterns_.INACTIVE_TEXT_FG,
|
|
|
|
-- font_spec = Common.normal_font_spec,
|
|
|
|
-- x_align = 'left',
|
|
|
|
-- y_align = 'center',
|
|
|
|
-- 'Page Cache',
|
|
|
|
-- 'Buffers',
|
|
|
|
-- 'Kernel Slab'
|
|
|
|
-- },
|
|
|
|
-- percents = _G_Widget_.TextColumn{
|
|
|
|
-- x = _RIGHT_X_,
|
|
|
|
-- y = _LINE_1_Y_ + _TEXT_SPACING_,
|
|
|
|
-- x_align = 'right',
|
|
|
|
-- y_align = 'center',
|
|
|
|
-- append_end = ' %',
|
|
|
|
-- text_color = _G_Patterns_.SECONDARY_FG,
|
|
|
|
-- font_spec = Common.normal_font_spec,
|
|
|
|
-- '<cached_kb>',
|
|
|
|
-- '<buffers_kb>',
|
|
|
|
-- '<kernel_slab>'
|
|
|
|
-- },
|
|
|
|
-- }
|
2017-07-19 00:36:15 -04:00
|
|
|
local cache = {
|
2021-07-09 22:22:49 -04:00
|
|
|
labels = _G_Widget_.TextColumn(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(
|
|
|
|
_TEXT_LEFT_X_,
|
|
|
|
_LINE_1_Y_ + _TEXT_SPACING_
|
|
|
|
),
|
2021-07-10 17:13:17 -04:00
|
|
|
{'Page Cache', 'Buffers', 'Kernel Slab'},
|
|
|
|
_G_Widget_.text_style(
|
|
|
|
Common.normal_font_spec,
|
|
|
|
_G_Patterns_.INACTIVE_TEXT_FG,
|
|
|
|
'left',
|
|
|
|
'center'
|
|
|
|
),
|
2021-07-10 22:50:30 -04:00
|
|
|
nil,
|
2021-07-10 17:13:17 -04:00
|
|
|
_TEXT_SPACING_
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
|
|
|
percents = _G_Widget_.initTextColumnN(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(
|
|
|
|
_RIGHT_X_,
|
|
|
|
_LINE_1_Y_ + _TEXT_SPACING_
|
|
|
|
),
|
2021-07-10 17:13:17 -04:00
|
|
|
3,
|
|
|
|
_G_Widget_.text_style(
|
|
|
|
Common.normal_font_spec,
|
|
|
|
_G_Patterns_.SECONDARY_FG,
|
|
|
|
'right',
|
|
|
|
'center'
|
|
|
|
),
|
2021-07-10 22:50:30 -04:00
|
|
|
'%s%%',
|
2021-07-10 17:13:17 -04:00
|
|
|
_TEXT_SPACING_
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local plot = Common.initThemedLabelPlot(
|
|
|
|
_G_INIT_DATA_.RIGHT_X,
|
|
|
|
_PLOT_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
2021-07-11 14:48:51 -04:00
|
|
|
_PLOT_HEIGHT_,
|
|
|
|
Common.percent_label_style
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
local tbl = Common.initTable(
|
|
|
|
_G_INIT_DATA_.RIGHT_X,
|
|
|
|
_PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_TABLE_HEIGHT_,
|
|
|
|
NUM_ROWS,
|
|
|
|
{'Name', 'PID', 'Mem (%)'}
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local update = function(cr)
|
2020-04-11 15:14:14 -04:00
|
|
|
local conky = Util.conky
|
|
|
|
-- see source for the 'free' command (sysinfo.c) for formulas
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB
|
|
|
|
|
|
|
|
Dial.set(dial, used_percent)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100))
|
2020-04-11 15:14:14 -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)
|
|
|
|
|
2021-07-05 23:27:43 -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
|
|
|
|
|
|
|
local _percents = cache.percents
|
|
|
|
|
|
|
|
TextColumn.set(_percents, cr, 1, Util.precision_round_to_string(
|
|
|
|
cached_kb / MEM_TOTAL_KB * 100))
|
|
|
|
|
|
|
|
TextColumn.set(_percents, cr, 2, Util.precision_round_to_string(
|
|
|
|
buffers_kb / MEM_TOTAL_KB * 100))
|
|
|
|
|
|
|
|
TextColumn.set(_percents, cr, 3, Util.precision_round_to_string(
|
|
|
|
slab_reclaimable_kb / MEM_TOTAL_KB * 100))
|
|
|
|
|
|
|
|
LabelPlot.update(plot, used_percent)
|
|
|
|
|
|
|
|
for r = 1, NUM_ROWS do
|
|
|
|
local comm = conky(TABLE_CONKY[r].comm, '(%S+)') -- may have trailing space
|
|
|
|
local pid = conky(TABLE_CONKY[r].pid)
|
|
|
|
local mem = conky(TABLE_CONKY[r].mem)
|
|
|
|
Table.set(tbl, cr, 1, r, comm)
|
|
|
|
Table.set(tbl, cr, 2, r, pid)
|
|
|
|
Table.set(tbl, cr, 3, r, mem)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
_MODULE_Y_ = nil
|
|
|
|
_DIAL_THICKNESS_ = nil
|
|
|
|
_DIAL_SPACING_ = nil
|
|
|
|
_TEXT_Y_OFFSET_ = nil
|
|
|
|
_TEXT_LEFT_X_OFFSET_ = nil
|
|
|
|
_TEXT_SPACING_ = nil
|
|
|
|
_PLOT_SECTION_BREAK_ = nil
|
|
|
|
_PLOT_HEIGHT_ = nil
|
|
|
|
_TABLE_SECTION_BREAK_ = nil
|
|
|
|
_TABLE_HEIGHT_ = nil
|
|
|
|
_LINE_1_Y_ = nil
|
|
|
|
_TEXT_LEFT_X_ = nil
|
|
|
|
_RIGHT_X_ = nil
|
|
|
|
_PLOT_Y_ = nil
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_static = function(cr)
|
|
|
|
Common.drawHeader(cr, header)
|
2018-08-05 11:35:00 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_ring_draw_static(text_ring, cr)
|
2018-08-05 14:45:41 -04:00
|
|
|
Dial.draw_static(dial, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_crit_draw_static(swap, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
TextColumn.draw(cache.labels, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_static(plot, cr)
|
2018-08-05 11:56:11 -04:00
|
|
|
|
|
|
|
Table.draw_static(tbl, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_dynamic = function(cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
update(cr)
|
|
|
|
|
2018-08-05 14:45:41 -04:00
|
|
|
Dial.draw_dynamic(dial, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
Arc.draw(cache_arc, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_ring_draw_dynamic(text_ring, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_crit_draw_dynamic(swap, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
TextColumn.draw(cache.percents, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_dynamic(plot, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2018-08-05 11:56:11 -04:00
|
|
|
Table.draw_dynamic(tbl, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
return M
|