From 7abefbe756d223c26d5576dfa378a23275a7ae14 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 2 Feb 2021 18:21:32 -0500 Subject: [PATCH] ADD smartd indicator --- drawing/FileSystem.lua | 86 +++++++++++++++++++++++++++++++----------- drawing/Power.lua | 23 +++++------ 2 files changed, 75 insertions(+), 34 deletions(-) diff --git a/drawing/FileSystem.lua b/drawing/FileSystem.lua index e3714f8..cd6e218 100644 --- a/drawing/FileSystem.lua +++ b/drawing/FileSystem.lua @@ -1,5 +1,6 @@ local M = {} +local Patterns = require 'Patterns' local Text = require 'Text' local Line = require 'Line' local TextColumn = require 'TextColumn' @@ -12,6 +13,7 @@ local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache'} local _MODULE_Y_ = 170 local _SPACING_ = 20 local _BAR_PAD_ = 100 +local _SEPARATOR_SPACING_ = 20 local FS_NUM = #_FS_PATHS_ @@ -22,9 +24,55 @@ local header = _G_Widget_.Header{ header = 'FILE SYSTEMS' } +local conky_used_perc = {} + +for i, v in pairs(_FS_PATHS_) do + conky_used_perc[i] = '${fs_used_perc '..v..'}' +end + +local smart = { + label = _G_Widget_.Text{ + x = _G_INIT_DATA_.RIGHT_X, + y = header.bottom_y, + text = 'SMART Daemon' + }, + value = _G_Widget_.Text{ + x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH, + y = header.bottom_y, + x_align = 'right', + text_color = Patterns.BLUE, + text = '', + } +} + +local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_ + +local separator = _G_Widget_.Line{ + p1 = { + x = _G_INIT_DATA_.RIGHT_X, + y = _SEP_Y_, + }, + p2 = { + x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH, + y = _SEP_Y_, + } +} + +local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ + +local bars = _G_Widget_.CompoundBar{ + x = _G_INIT_DATA_.RIGHT_X + _BAR_PAD_, + y = _BAR_Y_, + length = _G_INIT_DATA_.SECTION_WIDTH - _BAR_PAD_, + spacing = _SPACING_, + num_bars = FS_NUM, + -- thickness = 12, + critical_limit = '>0.8' +} + local labels = _G_Widget_.TextColumn{ x = _G_INIT_DATA_.RIGHT_X, - y = header.bottom_y, + y = _BAR_Y_, spacing = _SPACING_, 'root', 'boot', @@ -33,37 +81,31 @@ local labels = _G_Widget_.TextColumn{ 'dcache', } -local conky_used_perc = {} - -for i, v in pairs(_FS_PATHS_) do - conky_used_perc[i] = '${fs_used_perc '..v..'}' -end - -local bars = _G_Widget_.CompoundBar{ - x = _G_INIT_DATA_.RIGHT_X + _BAR_PAD_, - y = header.bottom_y, - length = _G_INIT_DATA_.SECTION_WIDTH - _BAR_PAD_, - spacing = _SPACING_, - num_bars = FS_NUM, - -- thickness = 12, - critical_limit = '>0.8' -} - _SPACING_ = nil _BAR_PAD_ = nil _FS_PATHS_ = nil +_SEPARATOR_SPACING_ = nil +_BAR_Y_ = nil +_SEPARATOR_SPACING_ = nil +_SEP_Y_ = nil local update = function(cr) - for i = 1, FS_NUM do - local percent = Util.conky_numeric(conky_used_perc[i]) - CompoundBar.set(bars, i, percent * 0.01) - end + local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n') + Text.set(smart.value, cr, (smart_pid == '') and 'Error' or 'Running') + + for i = 1, FS_NUM do + local percent = Util.conky_numeric(conky_used_perc[i]) + CompoundBar.set(bars, i, percent * 0.01) + end end local draw_static = function(cr) Text.draw(header.text, cr) Line.draw(header.underline, cr) + Text.draw(smart.label, cr) + Line.draw(separator, cr) + TextColumn.draw(labels, cr) CompoundBar.draw_static(bars, cr) end @@ -71,6 +113,8 @@ end local draw_dynamic = function(cr, trigger) if trigger == 0 then update(cr) end + Text.draw(smart.value, cr) + CompoundBar.draw_dynamic(bars, cr) end diff --git a/drawing/Power.lua b/drawing/Power.lua index 65d7796..09690bf 100644 --- a/drawing/Power.lua +++ b/drawing/Power.lua @@ -7,10 +7,10 @@ local Line = require 'Line' local ScalePlot = require 'ScalePlot' local Util = require 'Util' -local _MODULE_Y_ = 320 +local _MODULE_Y_ = 364 local _TEXT_SPACING_ = 20 local _PLOT_SEC_BREAK_ = 20 -local _PLOT_HEIGHT_ = 73 +local _PLOT_HEIGHT_ = 56 local power_label_function = function(watts) return watts..' W' end @@ -33,17 +33,17 @@ local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH local pkg0 = { label = _G_Widget_.Text{ - x = _G_INIT_DATA_.RIGHT_X, - y = header.bottom_y, + x = _G_INIT_DATA_.RIGHT_X, + y = header.bottom_y, text = 'PKG0', }, value = _G_Widget_.Text{ - x = _RIGHT_X_, - y = header.bottom_y, - x_align = 'right', - text_color = Patterns.BLUE, - text = '', - append_end = ' W', + x = _RIGHT_X_, + y = header.bottom_y, + x_align = 'right', + text_color = Patterns.BLUE, + text = '', + append_end = ' W', }, plot = _G_Widget_.ScalePlot{ x = _G_INIT_DATA_.RIGHT_X, @@ -51,7 +51,6 @@ local pkg0 = { width = _G_INIT_DATA_.SECTION_WIDTH, height = _PLOT_HEIGHT_, y_label_func = power_label_function, - num_y_intrvl = 5, }, } @@ -77,7 +76,6 @@ local dram = { width = _G_INIT_DATA_.SECTION_WIDTH, height = _PLOT_HEIGHT_, y_label_func = power_label_function, - num_y_intrvl = 5, } } @@ -101,7 +99,6 @@ local battery_draw = { width = _G_INIT_DATA_.SECTION_WIDTH, height = _PLOT_HEIGHT_, y_label_func = power_label_function, - num_y_intrvl = 5, } }