2021-08-08 15:58:53 -04:00
|
|
|
local format = require 'format'
|
2022-07-14 22:25:47 -04:00
|
|
|
local pure = require 'pure'
|
2021-08-08 15:58:53 -04:00
|
|
|
local i_o = require 'i_o'
|
2021-08-08 19:12:31 -04:00
|
|
|
local sys = require 'sys'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2022-07-17 18:40:24 -04:00
|
|
|
return function(update_freq, common, width, point)
|
2021-07-18 00:03:44 -04:00
|
|
|
local PLOT_SEC_BREAK = 20
|
|
|
|
local PLOT_HEIGHT = 56
|
2021-08-08 19:12:31 -04:00
|
|
|
local INTERFACE_PATHS = sys.get_net_interface_paths()
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local get_bits = function(path)
|
2021-08-08 15:58:53 -04:00
|
|
|
return i_o.read_file(path, nil, '*n') * 8
|
2021-07-19 23:58:58 -04:00
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-14 22:25:47 -04:00
|
|
|
local state = {rx_bits = 0, tx_bits = 0}
|
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local read_interfaces = function()
|
2022-07-14 22:25:47 -04:00
|
|
|
state.rx_bits = 0
|
|
|
|
state.tx_bits = 0
|
2021-07-19 23:58:58 -04:00
|
|
|
for i = 1, #INTERFACE_PATHS do
|
|
|
|
local p = INTERFACE_PATHS[i]
|
2022-07-14 22:25:47 -04:00
|
|
|
state.rx_bits = state.rx_bits + get_bits(p.rx)
|
|
|
|
state.tx_bits = state.tx_bits + get_bits(p.tx)
|
2021-07-19 23:58:58 -04:00
|
|
|
end
|
2022-07-14 22:25:47 -04:00
|
|
|
return state
|
2021-07-19 23:58:58 -04:00
|
|
|
end
|
|
|
|
|
2022-07-14 22:25:47 -04:00
|
|
|
-- prime initial state
|
|
|
|
read_interfaces()
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-18 00:03:44 -04:00
|
|
|
local value_format_function = function(bits)
|
2021-08-08 15:58:53 -04:00
|
|
|
local unit, value = format.convert_data_val(bits)
|
|
|
|
return format.precision_round_to_string(value, 3)..' '..unit..'b/s'
|
2021-07-18 00:03:44 -04:00
|
|
|
end
|
|
|
|
|
2022-07-14 22:49:08 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- down/up plots
|
|
|
|
|
2022-07-14 22:25:47 -04:00
|
|
|
local mk_plot = function(label, key, y)
|
|
|
|
local obj = common.make_rate_timeseries(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2021-07-18 00:03:44 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2021-07-18 00:03:44 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
value_format_function,
|
2021-07-29 22:18:29 -04:00
|
|
|
common.converted_y_label_format_generator('b'),
|
2021-07-18 00:03:44 -04:00
|
|
|
PLOT_SEC_BREAK,
|
|
|
|
label,
|
|
|
|
2,
|
2021-07-19 23:58:58 -04:00
|
|
|
update_freq,
|
2022-07-14 22:25:47 -04:00
|
|
|
state[key]
|
|
|
|
)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-14 22:25:47 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
|
|
|
function(s) common.update_rate_timeseries(obj, s[key]) end,
|
|
|
|
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
|
|
|
|
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
|
2021-07-18 00:03:44 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-07-14 22:25:47 -04:00
|
|
|
local mk_rx = pure.partial(mk_plot, 'Download', 'rx_bits')
|
|
|
|
local mk_tx = pure.partial(mk_plot, 'Upload', 'tx_bits')
|
2021-07-18 01:31:51 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- main drawing functions
|
2021-07-18 00:03:44 -04:00
|
|
|
|
2022-07-17 19:12:31 -04:00
|
|
|
return {
|
|
|
|
header = 'NETWORK',
|
|
|
|
point = point,
|
|
|
|
width = width,
|
|
|
|
update_wrapper = function(f) return function(_) f(read_interfaces()) end end,
|
|
|
|
top = {
|
2022-07-16 23:48:01 -04:00
|
|
|
{mk_rx, true, PLOT_SEC_BREAK},
|
|
|
|
{mk_tx, true, 0},
|
2022-07-14 22:25:47 -04:00
|
|
|
}
|
2022-07-17 19:12:31 -04:00
|
|
|
}
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|