ENH move a bunch of stuff to core
This commit is contained in:
parent
2600b871ac
commit
f13e01c7b4
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 9291f832df10f881852cddd15bf9520a4cd1ad3a
|
Subproject commit 4da966c53f54d9438a012607aba3100fedafa2fb
|
|
@ -2,9 +2,10 @@ local line = require 'line'
|
||||||
local i_o = require 'i_o'
|
local i_o = require 'i_o'
|
||||||
local common = require 'common'
|
local common = require 'common'
|
||||||
local geometry = require 'geometry'
|
local geometry = require 'geometry'
|
||||||
|
local pure = require 'pure'
|
||||||
|
local impure = require 'impure'
|
||||||
|
|
||||||
return function()
|
return function(paths)
|
||||||
local FS_PATHS = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
|
|
||||||
local MODULE_Y = 170
|
local MODULE_Y = 170
|
||||||
local SPACING = 20
|
local SPACING = 20
|
||||||
local BAR_PAD = 100
|
local BAR_PAD = 100
|
||||||
|
@ -54,10 +55,13 @@ return function()
|
||||||
0.8
|
0.8
|
||||||
)
|
)
|
||||||
|
|
||||||
local FS_NUM = #FS_PATHS
|
local CONKY_CMDS = pure.map(
|
||||||
local CONKY_USED_PERC = {}
|
pure.partial(string.format, '${fs_used_perc %s}', true),
|
||||||
for i, v in pairs(FS_PATHS) do
|
paths
|
||||||
CONKY_USED_PERC[i] = '${fs_used_perc '..v..'}'
|
)
|
||||||
|
|
||||||
|
local read_fs = function(index, cmd)
|
||||||
|
common.compound_bar_set(fs, index, i_o.conky_numeric(cmd) * 0.01)
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -67,11 +71,7 @@ return function()
|
||||||
if trigger == 0 then
|
if trigger == 0 then
|
||||||
local smart_pid = i_o.execute_cmd('pidof smartd', nil, '*n')
|
local smart_pid = i_o.execute_cmd('pidof smartd', nil, '*n')
|
||||||
common.text_row_set(smart, (smart_pid == '') and 'Error' or 'Running')
|
common.text_row_set(smart, (smart_pid == '') and 'Error' or 'Running')
|
||||||
|
impure.ieach(read_fs, CONKY_CMDS)
|
||||||
for i = 1, FS_NUM do
|
|
||||||
local percent = i_o.conky_numeric(CONKY_USED_PERC[i])
|
|
||||||
common.compound_bar_set(fs, i, percent * 0.01)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ return function(update_freq)
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
local NA = 'N/A'
|
local NA = 'N/A'
|
||||||
local __string_match = string.match
|
local __string_match = string.match
|
||||||
local __string_format = string.format
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -111,7 +111,7 @@ return function(update_freq)
|
||||||
-- memory top table
|
-- memory top table
|
||||||
|
|
||||||
local NUM_ROWS = 5
|
local NUM_ROWS = 5
|
||||||
local TABLE_CONKY = pure.map(
|
local TABLE_CONKY = pure.map_n(
|
||||||
function(i)
|
function(i)
|
||||||
return {
|
return {
|
||||||
comm = '${top_mem name '..i..'}',
|
comm = '${top_mem name '..i..'}',
|
||||||
|
@ -119,7 +119,7 @@ return function(update_freq)
|
||||||
mem = '${top_mem mem '..i..'}',
|
mem = '${top_mem mem '..i..'}',
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
pure.seq(NUM_ROWS))
|
NUM_ROWS)
|
||||||
|
|
||||||
local tbl = common.make_text_table(
|
local tbl = common.make_text_table(
|
||||||
geometry.RIGHT_X,
|
geometry.RIGHT_X,
|
||||||
|
|
|
@ -2,30 +2,12 @@ local format = require 'format'
|
||||||
local i_o = require 'i_o'
|
local i_o = require 'i_o'
|
||||||
local common = require 'common'
|
local common = require 'common'
|
||||||
local geometry = require 'geometry'
|
local geometry = require 'geometry'
|
||||||
local pure = require 'pure'
|
local sys = require 'sys'
|
||||||
|
|
||||||
return function(update_freq)
|
return function(update_freq)
|
||||||
local PLOT_SEC_BREAK = 20
|
local PLOT_SEC_BREAK = 20
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
|
local INTERFACE_PATHS = sys.get_net_interface_paths()
|
||||||
local get_interfaces = function()
|
|
||||||
local s = i_o.execute_cmd('realpath /sys/class/net/* | grep -v virtual')
|
|
||||||
local interfaces = {}
|
|
||||||
for iface in string.gmatch(s, '/([^/\n]+)\n') do
|
|
||||||
interfaces[#interfaces + 1] = iface
|
|
||||||
end
|
|
||||||
return interfaces
|
|
||||||
end
|
|
||||||
|
|
||||||
local INTERFACES = get_interfaces()
|
|
||||||
|
|
||||||
local INTERFACE_PATHS = pure.map(
|
|
||||||
function(s)
|
|
||||||
local dir = string.format('/sys/class/net/%s/statistics/', s)
|
|
||||||
return {rx = dir..'rx_bytes', tx = dir..'tx_bytes'}
|
|
||||||
end,
|
|
||||||
INTERFACES
|
|
||||||
)
|
|
||||||
|
|
||||||
local get_bits = function(path)
|
local get_bits = function(path)
|
||||||
return i_o.read_file(path, nil, '*n') * 8
|
return i_o.read_file(path, nil, '*n') * 8
|
||||||
|
|
|
@ -1,43 +1,24 @@
|
||||||
local format = require 'format'
|
local format = require 'format'
|
||||||
local i_o = require 'i_o'
|
-- local i_o = require 'i_o'
|
||||||
local common = require 'common'
|
local common = require 'common'
|
||||||
local geometry = require 'geometry'
|
local geometry = require 'geometry'
|
||||||
|
local sys = require 'sys'
|
||||||
|
|
||||||
return function(update_freq)
|
return function(update_freq, battery)
|
||||||
local MODULE_Y = 380
|
local MODULE_Y = 380
|
||||||
local TEXT_SPACING = 20
|
local TEXT_SPACING = 20
|
||||||
local PLOT_SEC_BREAK = 20
|
local PLOT_SEC_BREAK = 20
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
|
local read_pkg0_joules = sys.intel_powercap_reader('intel-rapl:0')
|
||||||
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
|
local read_dram_joules = sys.intel_powercap_reader('intel-rapl:0:2')
|
||||||
local BAT_CURRENT_PATH = '/sys/class/power_supply/BAT0/current_now'
|
|
||||||
local BAT_VOLTAGE_PATH = '/sys/class/power_supply/BAT0/voltage_now'
|
|
||||||
|
|
||||||
local read_milli = function(path)
|
local _read_battery_power = sys.battery_power_reader(battery)
|
||||||
return i_o.read_file(path, nil, '*n') * 0.000001
|
|
||||||
end
|
|
||||||
|
|
||||||
local read_pkg0_joules = function()
|
|
||||||
return read_milli(PKG0_PATH)
|
|
||||||
end
|
|
||||||
|
|
||||||
local read_dram_joules = function()
|
|
||||||
return read_milli(DRAM_PATH)
|
|
||||||
end
|
|
||||||
|
|
||||||
local read_battery_current = function()
|
|
||||||
return read_milli(BAT_CURRENT_PATH)
|
|
||||||
end
|
|
||||||
|
|
||||||
local read_battery_voltage = function()
|
|
||||||
return read_milli(BAT_VOLTAGE_PATH)
|
|
||||||
end
|
|
||||||
|
|
||||||
local read_battery_power = function(is_using_ac)
|
local read_battery_power = function(is_using_ac)
|
||||||
if is_using_ac then
|
if is_using_ac then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return read_battery_current() * read_battery_voltage()
|
return _read_battery_power()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,14 @@
|
||||||
local i_o = require 'i_o'
|
|
||||||
local format = require 'format'
|
local format = require 'format'
|
||||||
local common = require 'common'
|
local common = require 'common'
|
||||||
local geometry = require 'geometry'
|
local geometry = require 'geometry'
|
||||||
local pure = require 'pure'
|
local sys = require 'sys'
|
||||||
|
|
||||||
return function(update_freq)
|
return function(update_freq, devices)
|
||||||
local PLOT_SEC_BREAK = 20
|
local PLOT_SEC_BREAK = 20
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
local DEVICES = {'sda', 'nvme0n1'}
|
local DEVICE_PATHS = sys.get_disk_paths(devices)
|
||||||
|
|
||||||
-- the sector size of any block device in linux is 512 bytes
|
local init_read_bytes, init_write_bytes = sys.get_total_disk_io(DEVICE_PATHS)
|
||||||
-- see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/types.h?id=v4.4-rc6#n121
|
|
||||||
local BLOCK_SIZE_BYTES = 512
|
|
||||||
|
|
||||||
-- fields 3 and 7 (sectors read and written)
|
|
||||||
local RW_REGEX = '%s+%d+%s+%d+%s+(%d+)%s+%d+%s+%d+%s+%d+%s+(%d+)'
|
|
||||||
|
|
||||||
local __tonumber = tonumber
|
|
||||||
local __string_match = string.match
|
|
||||||
|
|
||||||
local DEVICE_PATHS = pure.map(
|
|
||||||
pure.partial(string.format, '/sys/block/%s/stat', true),
|
|
||||||
DEVICES
|
|
||||||
)
|
|
||||||
|
|
||||||
local read_devices = function()
|
|
||||||
local read_bytes = 0
|
|
||||||
local write_bytes = 0
|
|
||||||
for _, path in pairs(DEVICE_PATHS) do
|
|
||||||
local r, w = __string_match(i_o.read_file(path), RW_REGEX)
|
|
||||||
read_bytes = read_bytes + __tonumber(r)
|
|
||||||
write_bytes = write_bytes + __tonumber(w)
|
|
||||||
end
|
|
||||||
return read_bytes * BLOCK_SIZE_BYTES, write_bytes * BLOCK_SIZE_BYTES
|
|
||||||
end
|
|
||||||
|
|
||||||
local init_read_bytes, init_write_bytes = read_devices()
|
|
||||||
|
|
||||||
local format_value_function = function(bps)
|
local format_value_function = function(bps)
|
||||||
local unit, value = format.convert_data_val(bps)
|
local unit, value = format.convert_data_val(bps)
|
||||||
|
@ -86,7 +59,7 @@ return function(update_freq)
|
||||||
-- main drawing functions
|
-- main drawing functions
|
||||||
|
|
||||||
local update = function()
|
local update = function()
|
||||||
local read_bytes, write_bytes = read_devices()
|
local read_bytes, write_bytes = sys.get_total_disk_io(DEVICE_PATHS)
|
||||||
common.update_rate_timeseries(reads, read_bytes)
|
common.update_rate_timeseries(reads, read_bytes)
|
||||||
common.update_rate_timeseries(writes, write_bytes)
|
common.update_rate_timeseries(writes, write_bytes)
|
||||||
end
|
end
|
||||||
|
|
26
main.lua
26
main.lua
|
@ -17,6 +17,7 @@ package.path = ABS_PATH..'?.lua;'..
|
||||||
ABS_PATH..'core/widget/line/?.lua;'
|
ABS_PATH..'core/widget/line/?.lua;'
|
||||||
|
|
||||||
local i_o = require 'i_o'
|
local i_o = require 'i_o'
|
||||||
|
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'
|
||||||
|
@ -28,31 +29,30 @@ local graphics = require 'graphics'
|
||||||
local memory = require 'memory'
|
local memory = require 'memory'
|
||||||
local static = require 'static'
|
local static = require 'static'
|
||||||
|
|
||||||
local using_ac = function()
|
|
||||||
-- for some reason it is much more efficient to test if the battery
|
|
||||||
-- is off than if the ac is on
|
|
||||||
return i_o.read_file('/sys/class/power_supply/BAT0/status', nil, '*l') ~= 'Discharging'
|
|
||||||
end
|
|
||||||
|
|
||||||
local draw_dynamic
|
local draw_dynamic
|
||||||
|
|
||||||
function conky_start(update_interval)
|
function conky_start(update_interval)
|
||||||
conky_set_update_interval(update_interval)
|
conky_set_update_interval(update_interval)
|
||||||
|
|
||||||
local update_freq = 1 / update_interval
|
local update_freq = 1 / update_interval
|
||||||
|
local devices = {'sda', 'nvme0n1'}
|
||||||
|
local battery = 'BAT0'
|
||||||
|
local fs_paths = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
|
||||||
|
|
||||||
local mem = memory(update_freq)
|
local mem = memory(update_freq)
|
||||||
local rw = readwrite(update_freq)
|
local rw = readwrite(update_freq, devices)
|
||||||
local net = network(update_freq)
|
local net = network(update_freq)
|
||||||
local pwr = power(update_freq)
|
local pwr = power(update_freq)
|
||||||
local fs = filesystem()
|
local fs = filesystem(fs_paths)
|
||||||
local sys = system()
|
local stm = system()
|
||||||
local gfx = graphics(update_freq)
|
local gfx = graphics(update_freq)
|
||||||
local proc = processor(update_freq)
|
local proc = processor(update_freq)
|
||||||
local pcm = pacman()
|
local pcm = pacman()
|
||||||
|
|
||||||
|
local using_ac = sys.battery_status_reader(battery)
|
||||||
|
|
||||||
local draw_static = static(
|
local draw_static = static(
|
||||||
{sys.static, gfx.static, proc.static},
|
{stm.static, gfx.static, proc.static},
|
||||||
{rw.static, net.static},
|
{rw.static, net.static},
|
||||||
{pcm.static, fs.static, pwr.static, mem.static}
|
{pcm.static, fs.static, pwr.static, mem.static}
|
||||||
)
|
)
|
||||||
|
@ -68,18 +68,18 @@ function conky_start(update_interval)
|
||||||
local pacman_stats = i_o.read_file(STATS_FILE)
|
local pacman_stats = i_o.read_file(STATS_FILE)
|
||||||
local is_using_ac = using_ac()
|
local is_using_ac = using_ac()
|
||||||
|
|
||||||
sys.update(pacman_stats)
|
stm.update(pacman_stats)
|
||||||
gfx.update()
|
gfx.update()
|
||||||
proc.update(t1)
|
proc.update(t1)
|
||||||
rw.update()
|
rw.update()
|
||||||
net.update()
|
net.update()
|
||||||
pcm.update(pacman_stats)
|
pcm.update(pacman_stats)
|
||||||
fs.update(t1)
|
fs.update(t1)
|
||||||
pwr.update(is_using_ac)
|
pwr.update(is_using_ac, battery)
|
||||||
mem.update()
|
mem.update()
|
||||||
|
|
||||||
-- draw dynamic components
|
-- draw dynamic components
|
||||||
sys.dynamic(cr)
|
stm.dynamic(cr)
|
||||||
gfx.dynamic(cr)
|
gfx.dynamic(cr)
|
||||||
proc.dynamic(cr)
|
proc.dynamic(cr)
|
||||||
rw.dynamic(cr)
|
rw.dynamic(cr)
|
||||||
|
|
Loading…
Reference in New Issue