ENH use yaml config

This commit is contained in:
Nathan Dwarshuis 2022-07-17 01:25:53 -04:00
parent 9365196073
commit fef8f9c80e
7 changed files with 223 additions and 65 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

48
config.yml Normal file
View File

@ -0,0 +1,48 @@
modules:
filesystem:
show_smart: true
fs_paths:
- path: /
name: root
- path: /boot
name: boot
- path: /home
name: home
- path: /mnt/data
name: data
- path: /mnt/dcache
name: dcache
- path: /tmp
name: tmpfs
graphics:
show_temp: true
show_clock: true
show_gpu_util: true
show_mem_util: true
show_vid_util: true
memory:
show_stats: true
show_plot: true
show_table: true
power:
battery: BAT0
rapl_specs:
- name: PKG0
address: intel-rapl:0
- name: DRAM
address: intel-rapl:0:2
processor:
show_cores: true
show_stats: true
show_plot: true
show_table: true
readwrite:
devices: [sda, nvme0n1]
layout:
anchor: [12, 11]
panels:
- !!seq [[system, 19, graphics, 16, processor]]
- 10
- !!seq [[readwrite], 20, [network]]
- 10
- !!seq [[pacman, 24, filesystem, 24, power, 19, memory]]

View File

@ -6,9 +6,6 @@ local impure = require 'impure'
-- ASSUME pathspecs will be at least 1 long -- ASSUME pathspecs will be at least 1 long
return function(config, main_state, point) return function(config, main_state, point)
-- local config = {
-- show_smart = true
-- }
local SPACING = 20 local SPACING = 20
local BAR_PAD = 100 local BAR_PAD = 100
local SEPARATOR_SPACING = 20 local SEPARATOR_SPACING = 20
@ -48,7 +45,9 @@ return function(config, main_state, point)
-- filesystem bar chart -- filesystem bar chart
local mk_bars = function(y) local mk_bars = function(y)
local paths, names = table.unpack(pure.unzip(config.fs_paths)) local paths = pure.map_keys('path', config.fs_paths)
local names = pure.map_keys('name', config.fs_paths)
-- local paths, names = table.unpack(pure.unzip(config.fs_paths))
local CONKY_CMDS = pure.map( local CONKY_CMDS = pure.map(
pure.partial(string.format, '${fs_used_perc %s}', true), pure.partial(string.format, '${fs_used_perc %s}', true),
paths paths
@ -89,8 +88,5 @@ return function(config, main_state, point)
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
{{mk_smart, config.show_smart, SEPARATOR_SPACING}}, {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
common.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0}) common.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0})
-- common.mk_block(mk_sep, config.show_smart, SEPARATOR_SPACING),
-- common.mk_block(mk_bars, true, 0),
-- }
) )
end end

View File

@ -4,13 +4,6 @@ local common = require 'common'
local geometry = require 'geometry' local geometry = require 'geometry'
return function(update_freq, config, point) return function(update_freq, config, point)
-- local config = {
-- show_temp = true,
-- show_clock = true,
-- show_gpu_util = true,
-- show_mem_util = true,
-- show_vid_util = true
-- }
local SEPARATOR_SPACING = 20 local SEPARATOR_SPACING = 20
local TEXT_SPACING = 20 local TEXT_SPACING = 20
local PLOT_SEC_BREAK = 20 local PLOT_SEC_BREAK = 20

View File

@ -51,7 +51,7 @@ return function(update_freq, config, point)
end end
local mk_rate_blockspec = function(spec) local mk_rate_blockspec = function(spec)
local f = pure.partial(mk_rate_plot, table.unpack(spec)) local f = pure.partial(mk_rate_plot, spec.name, spec.address)
return {f, true, TEXT_SPACING} return {f, true, TEXT_SPACING}
end end

View File

@ -14,12 +14,12 @@ package.path = ABS_PATH..'?.lua;'..
ABS_PATH..'core/widget/text/?.lua;'.. ABS_PATH..'core/widget/text/?.lua;'..
ABS_PATH..'core/widget/timeseries/?.lua;'.. ABS_PATH..'core/widget/timeseries/?.lua;'..
ABS_PATH..'core/widget/rect/?.lua;'.. ABS_PATH..'core/widget/rect/?.lua;'..
ABS_PATH..'core/widget/line/?.lua;' ABS_PATH..'core/widget/line/?.lua;'..
ABS_PATH..'lib/share/lua/5.4/?.lua;'
local i_o = require 'i_o' local i_o = require 'i_o'
local geom = require 'geom' local geom = require 'geom'
local pure = require 'pure' local pure = require 'pure'
local sys = require 'sys'
local system = require 'system' local system = require 'system'
local network = require 'network' local network = require 'network'
local processor = require 'processor' local processor = require 'processor'
@ -30,6 +30,7 @@ local readwrite = require 'readwrite'
local graphics = require 'graphics' local graphics = require 'graphics'
local memory = require 'memory' local memory = require 'memory'
local static = require 'static' local static = require 'static'
local yaml = require 'tinyyaml'
local draw_dynamic local draw_dynamic
@ -40,60 +41,21 @@ function conky_start(update_interval)
local main_state = {} local main_state = {}
local config = { local config = yaml.parse(i_o.read_file(ABS_PATH..'config.yml'))
filesystem = { local cmods = config.modules
show_smart = true,
fs_paths = {
{'/', 'root'},
{'/boot', 'boot'},
{'/home', 'home'},
{'/mnt/data', 'data'},
{'/mnt/dcache', 'dcache'},
{'/tmp', 'tmpfs'}
}
},
graphics = {
show_temp = true,
show_clock = true,
show_gpu_util = true,
show_mem_util = true,
show_vid_util = true
},
memory = {
show_stats = true,
show_plot = true,
show_table = true,
},
power = {
battery = 'BAT0',
rapl_specs = {
{'PKG0', 'intel-rapl:0'},
{'DRAM', 'intel-rapl:0:2'}
}
},
processor = {
show_cores = true,
show_stats = true,
show_plot = true,
show_table = true,
},
readwrite = {
devices = {'sda', 'nvme0n1'},
},
}
local mem = pure.partial(memory, update_freq, config.memory) local mem = pure.partial(memory, update_freq, cmods.memory)
local rw = pure.partial(readwrite, update_freq, config.readwrite) local rw = pure.partial(readwrite, update_freq, cmods.readwrite)
local net = pure.partial(network, update_freq) local net = pure.partial(network, update_freq)
local pwr = pure.partial(power, update_freq, config.power) local pwr = pure.partial(power, update_freq, cmods.power)
local fs = pure.partial(filesystem, config.filesystem, main_state) local fs = pure.partial(filesystem, cmods.filesystem, main_state)
local stm = pure.partial(system, main_state) local stm = pure.partial(system, main_state)
local gfx = pure.partial(graphics, update_freq, config.graphics) local gfx = pure.partial(graphics, update_freq, cmods.graphics)
local proc = pure.partial(processor, update_freq, config.processor, main_state) local proc = pure.partial(processor, update_freq, cmods.processor, main_state)
local pcm = pure.partial(pacman, main_state) local pcm = pure.partial(pacman, main_state)
local compiled = static( local compiled = static(
geom.make_point(12, 11), geom.make_point(table.unpack(config.layout.anchor)),
{ {
{{stm, 19, gfx, 16, proc}}, {{stm, 19, gfx, 16, proc}},
10, 10,

158
schema.yml Normal file
View File

@ -0,0 +1,158 @@
$schema: "http://json-schema.org/draft-07/schema#"
description: over-engineered conky schema
required: [modules, layout]
additionalProperties: false
properties:
modules:
additionalProperties: false
properties:
filesystem:
required: [show_smart, fs_paths]
additionalProperties: false
properties:
show_smart:
description: show the smart deamon indicator
type: boolean
fs_paths:
description: the filesystem paths for which usage should be shown
type: array
minItems: 1
items:
type: object
required: [name, path]
additionalProperties: false
properties:
name:
type: string
path:
type: string
graphics:
required: [show_temp, show_clock, show_gpu_util, show_mem_util, show_vid_util]
additionalProperties: false
properties:
show_temp:
description: show the GPU temp
type: boolean
show_clock:
description: show the GPU clock speeds
type: boolean
show_gpu_util:
description: show the GPU utilization plot
type: boolean
show_mem_util:
description: show the GPU memory utilization plot
type: boolean
show_vid_util:
description: show the GPU video utilization plot
type: boolean
memory:
required: [show_stats, show_plot, show_table]
additionalProperties: false
properties:
show_stats:
description: show memory stats/dial
type: boolean
show_plot:
description: show the RAM utilization plot
type: boolean
show_table:
description: show the memory process table
type: boolean
power:
required: [battery, rapl_specs]
additionalProperties: false
properties:
battery:
description: the battery device to use (if applicable)
anyOf:
- type: string
- type: "null"
rapl_specs:
description: the Intel RAPL specs for which plots should be made
type: array
items:
type: object
required: [name, address]
additionalProperties: false
properties:
name:
type: string
address:
type: string
processor:
required: [show_cores, show_stats, show_plot, show_table]
additionalProperties: false
properties:
show_cores:
description: show individual CPU cores
type: boolean
show_stats:
description: show frequency/HWP stats
type: boolean
show_plot:
description: show CPU utilization plot
type: boolean
show_table:
description: show the CPU process table
type: boolean
readwrite:
required: [devices]
additionalProperties: false
properties:
devices:
description: the devices to include in I/O summations
type: array
minItems: 1
items:
type: string
layout:
required: [anchor, panels]
additionalProperties: false
properties:
anchor:
description: the coordinates of the upper-left corner to anchor the app
type: array
minItems: 2
maxItems: 2
items:
type: integer
panels:
description: either a panel (array) or padding between panels (int)
type: array
items:
anyOf:
- type: integer
minimum: 0
- type: array
description: |
either a list of columns in a panel (array) or padding between
columns (int)
minItems: 1
items:
anyOf:
- type: integer
minimum: 0
- type: array
description: |
either a list of modules in a panel column (array) or
padding between modules
minItems: 1
items:
anyOf:
- type: integer
minimum: 0
- type: string
pattern:
"^system|graphics|processor|readwrite|\
network|pacman|filesystem|power|memory$"