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 common = require 'common'
|
||||
local geometry = require 'geometry'
|
||||
local pure = require 'pure'
|
||||
local impure = require 'impure'
|
||||
|
||||
return function()
|
||||
local FS_PATHS = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
|
||||
return function(paths)
|
||||
local MODULE_Y = 170
|
||||
local SPACING = 20
|
||||
local BAR_PAD = 100
|
||||
|
@ -54,10 +55,13 @@ return function()
|
|||
0.8
|
||||
)
|
||||
|
||||
local FS_NUM = #FS_PATHS
|
||||
local CONKY_USED_PERC = {}
|
||||
for i, v in pairs(FS_PATHS) do
|
||||
CONKY_USED_PERC[i] = '${fs_used_perc '..v..'}'
|
||||
local CONKY_CMDS = pure.map(
|
||||
pure.partial(string.format, '${fs_used_perc %s}', true),
|
||||
paths
|
||||
)
|
||||
|
||||
local read_fs = function(index, cmd)
|
||||
common.compound_bar_set(fs, index, i_o.conky_numeric(cmd) * 0.01)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -67,11 +71,7 @@ return function()
|
|||
if trigger == 0 then
|
||||
local smart_pid = i_o.execute_cmd('pidof smartd', nil, '*n')
|
||||
common.text_row_set(smart, (smart_pid == '') and 'Error' or 'Running')
|
||||
|
||||
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
|
||||
impure.ieach(read_fs, CONKY_CMDS)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ return function(update_freq)
|
|||
local PLOT_HEIGHT = 56
|
||||
local NA = 'N/A'
|
||||
local __string_match = string.match
|
||||
local __string_format = string.format
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
|
@ -111,7 +111,7 @@ return function(update_freq)
|
|||
-- memory top table
|
||||
|
||||
local NUM_ROWS = 5
|
||||
local TABLE_CONKY = pure.map(
|
||||
local TABLE_CONKY = pure.map_n(
|
||||
function(i)
|
||||
return {
|
||||
comm = '${top_mem name '..i..'}',
|
||||
|
@ -119,7 +119,7 @@ return function(update_freq)
|
|||
mem = '${top_mem mem '..i..'}',
|
||||
}
|
||||
end,
|
||||
pure.seq(NUM_ROWS))
|
||||
NUM_ROWS)
|
||||
|
||||
local tbl = common.make_text_table(
|
||||
geometry.RIGHT_X,
|
||||
|
|
|
@ -2,30 +2,12 @@ local format = require 'format'
|
|||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local geometry = require 'geometry'
|
||||
local pure = require 'pure'
|
||||
local sys = require 'sys'
|
||||
|
||||
return function(update_freq)
|
||||
local PLOT_SEC_BREAK = 20
|
||||
local PLOT_HEIGHT = 56
|
||||
|
||||
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 INTERFACE_PATHS = sys.get_net_interface_paths()
|
||||
|
||||
local get_bits = function(path)
|
||||
return i_o.read_file(path, nil, '*n') * 8
|
||||
|
|
|
@ -1,43 +1,24 @@
|
|||
local format = require 'format'
|
||||
local i_o = require 'i_o'
|
||||
-- local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local geometry = require 'geometry'
|
||||
local sys = require 'sys'
|
||||
|
||||
return function(update_freq)
|
||||
return function(update_freq, battery)
|
||||
local MODULE_Y = 380
|
||||
local TEXT_SPACING = 20
|
||||
local PLOT_SEC_BREAK = 20
|
||||
local PLOT_HEIGHT = 56
|
||||
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
|
||||
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
|
||||
local BAT_CURRENT_PATH = '/sys/class/power_supply/BAT0/current_now'
|
||||
local BAT_VOLTAGE_PATH = '/sys/class/power_supply/BAT0/voltage_now'
|
||||
local read_pkg0_joules = sys.intel_powercap_reader('intel-rapl:0')
|
||||
local read_dram_joules = sys.intel_powercap_reader('intel-rapl:0:2')
|
||||
|
||||
local read_milli = function(path)
|
||||
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 = sys.battery_power_reader(battery)
|
||||
|
||||
local read_battery_power = function(is_using_ac)
|
||||
if is_using_ac then
|
||||
return 0
|
||||
else
|
||||
return read_battery_current() * read_battery_voltage()
|
||||
return _read_battery_power()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,41 +1,14 @@
|
|||
local i_o = require 'i_o'
|
||||
local format = require 'format'
|
||||
local common = require 'common'
|
||||
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_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
|
||||
-- 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 init_read_bytes, init_write_bytes = sys.get_total_disk_io(DEVICE_PATHS)
|
||||
|
||||
local format_value_function = function(bps)
|
||||
local unit, value = format.convert_data_val(bps)
|
||||
|
@ -86,7 +59,7 @@ return function(update_freq)
|
|||
-- main drawing functions
|
||||
|
||||
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(writes, write_bytes)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local geometry = require 'geometry'
|
||||
|
||||
return function()
|
||||
|
|
26
main.lua
26
main.lua
|
@ -17,6 +17,7 @@ package.path = ABS_PATH..'?.lua;'..
|
|||
ABS_PATH..'core/widget/line/?.lua;'
|
||||
|
||||
local i_o = require 'i_o'
|
||||
local sys = require 'sys'
|
||||
local system = require 'system'
|
||||
local network = require 'network'
|
||||
local processor = require 'processor'
|
||||
|
@ -28,31 +29,30 @@ local graphics = require 'graphics'
|
|||
local memory = require 'memory'
|
||||
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
|
||||
|
||||
function conky_start(update_interval)
|
||||
conky_set_update_interval(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 rw = readwrite(update_freq)
|
||||
local rw = readwrite(update_freq, devices)
|
||||
local net = network(update_freq)
|
||||
local pwr = power(update_freq)
|
||||
local fs = filesystem()
|
||||
local sys = system()
|
||||
local fs = filesystem(fs_paths)
|
||||
local stm = system()
|
||||
local gfx = graphics(update_freq)
|
||||
local proc = processor(update_freq)
|
||||
local pcm = pacman()
|
||||
|
||||
local using_ac = sys.battery_status_reader(battery)
|
||||
|
||||
local draw_static = static(
|
||||
{sys.static, gfx.static, proc.static},
|
||||
{stm.static, gfx.static, proc.static},
|
||||
{rw.static, net.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 is_using_ac = using_ac()
|
||||
|
||||
sys.update(pacman_stats)
|
||||
stm.update(pacman_stats)
|
||||
gfx.update()
|
||||
proc.update(t1)
|
||||
rw.update()
|
||||
net.update()
|
||||
pcm.update(pacman_stats)
|
||||
fs.update(t1)
|
||||
pwr.update(is_using_ac)
|
||||
pwr.update(is_using_ac, battery)
|
||||
mem.update()
|
||||
|
||||
-- draw dynamic components
|
||||
sys.dynamic(cr)
|
||||
stm.dynamic(cr)
|
||||
gfx.dynamic(cr)
|
||||
proc.dynamic(cr)
|
||||
rw.dynamic(cr)
|
||||
|
|
Loading…
Reference in New Issue