conky-config/drawing/readwrite.lua

65 lines
1.9 KiB
Lua
Raw Normal View History

2021-08-08 15:58:53 -04:00
local format = require 'format'
2022-07-14 22:59:14 -04:00
local pure = require 'pure'
2021-08-08 19:12:31 -04:00
local sys = require 'sys'
2017-07-19 00:36:15 -04:00
return function(update_freq, config, common, width, point)
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
2017-07-19 00:36:15 -04:00
2022-07-17 22:30:38 -04:00
local mod_state = {read = 0, write = 0}
local device_paths = sys.get_disk_paths(config.devices)
local update_state = function()
mod_state.read, mod_state.write = sys.get_total_disk_io(device_paths)
end
local format_value_function = function(bps)
2021-08-08 15:58:53 -04:00
local unit, value = format.convert_data_val(bps)
return format.precision_round_to_string(value, 3)..' '..unit..'B/s'
end
2022-07-14 22:59:14 -04:00
-----------------------------------------------------------------------------
-- r/w plots
local mk_plot = function(label, key, y)
local obj = common.make_rate_timeseries(
point.x,
y,
width,
PLOT_HEIGHT,
format_value_function,
common.converted_y_label_format_generator('B'),
PLOT_SEC_BREAK,
label,
2,
2021-07-19 23:58:58 -04:00
update_freq,
2022-07-17 22:30:38 -04:00
mod_state[key]
2022-07-14 22:59:14 -04:00
)
2022-07-17 18:54:23 -04:00
return common.mk_acc(
2022-07-16 00:00:06 -04:00
-- TODO construct this more sanely without referring to hardcoded vars
width,
2022-07-14 22:59:14 -04:00
PLOT_HEIGHT + PLOT_SEC_BREAK,
2022-07-17 22:30:38 -04:00
function() common.update_rate_timeseries(obj, mod_state[key]) end,
2022-07-14 22:59:14 -04:00
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
)
end
2022-07-14 22:59:14 -04:00
local mk_reads = pure.partial(mk_plot, 'Reads', 'read')
local mk_writes = pure.partial(mk_plot, 'Writes', 'write')
2021-07-19 23:58:58 -04:00
-----------------------------------------------------------------------------
-- main drawing functions
return {
header = 'INPUT / OUTPUT',
point = point,
width = width,
2022-07-17 22:30:38 -04:00
set_state = update_state,
top = {
{mk_reads, true, PLOT_SEC_BREAK},
{mk_writes, true, 0},
}
}
2017-07-19 00:36:15 -04:00
end