Skip to content

Commit

Permalink
LCDProc cleanup pt 2. Issue #14571
Browse files Browse the repository at this point in the history
* Remove redundant functions already in base with the same output
* Leverage base functions where possible otherwise
* Start service on sync if it's stopped (comments suggested it should,
  but it didn't)
* Fix formatting on Matrix Orbital help text
* Cleanup some more unused code
  • Loading branch information
jim-p committed Jul 14, 2023
1 parent 425488a commit 07d37ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 68 deletions.
2 changes: 1 addition & 1 deletion sysutils/pfSense-pkg-LCDproc/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-LCDproc
PORTVERSION= 0.11
PORTVERSION= 0.11.1
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
16 changes: 3 additions & 13 deletions sysutils/pfSense-pkg-LCDproc/files/usr/local/pkg/lcdproc.inc
Expand Up @@ -50,17 +50,6 @@ function lcdproc_write_config($file, $text) {
fclose($handle);
}

function lcdproc_write_script($file, $text) {
$handle = fopen($file, 'wx');
if (!$handle) {
lcdproc_warn("Could not open {$file} for writing.");
exit;
}
fwrite($handle, $text);
fclose($handle);
chmod($file, 0755);
}

function validate_form_lcdproc($post, &$input_errors) {
if ($post['comport']) {
switch($post['comport']) {
Expand Down Expand Up @@ -524,6 +513,8 @@ EOD;
if (is_service_running(LCDPROC_SERVICE_NAME)) {
lcdproc_notice("Sync: Restarting the service");
restart_service(LCDPROC_SERVICE_NAME);
} else {
start_service(LCDPROC_SERVICE_NAME);
}
}

Expand All @@ -546,8 +537,7 @@ EOD;

function set_lcd_value($fieldname, $max, $default_value) {
global $config;
$lcdproc_config = $config['installedpackages']['lcdproc']['config'][0];
$value = $lcdproc_config[$fieldname];
$value = config_get_path("installedpackages/lcdproc/config/0/{$fieldname}");
$returnvalue = "";
if ($value != '' && $value != '-1') {
$realvalue = (int)($max * $value / 100);
Expand Down
63 changes: 11 additions & 52 deletions sysutils/pfSense-pkg-LCDproc/files/usr/local/pkg/lcdproc_client.php
Expand Up @@ -26,53 +26,12 @@
require_once("interfaces.inc");
require_once("pfsense-utils.inc");
require_once("ipsec.inc");
require_once("includes/functions.inc.php");
require_once("/usr/local/pkg/lcdproc.inc");
require_once("system.inc");

function get_pfstate() {
$matches = "";
$maxstates = '/';
if ((int) config_get_path('system/maximumstates', 0) > 0) {
$maxstates .= config_get_path('system/maximumstates');
} else {
$maxstates .= pfsense_default_state_size();
}
$curentries = shell_exec('/sbin/pfctl -si | /usr/bin/grep current');
if (preg_match("/([0-9]+)/", $curentries, $matches)) {
$curentries = $matches[1];
}
return $curentries . $maxstates;
}

function disk_usage() {
$dfout = "";
exec("/bin/df -h | /usr/bin/grep -w '/' | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d '%' -f 1", $dfout);
$diskusage = trim($dfout[0]);

return $diskusage;
}

function mem_usage() {
$memUsage = "NA";
$totalMem = (int) get_single_sysctl("vm.stats.vm.v_page_count");
if (is_numeric($totalMem)) {
/* Include inactive and laundry with free memory since they
* could be freed under pressure. */
$inactiveMem = (int) get_single_sysctl("vm.stats.vm.v_inactive_count");
$laundryMem = (int) get_single_sysctl("vm.stats.vm.v_laundry_count");
$freeMem = (int) get_single_sysctl("vm.stats.vm.v_free_count");
if (is_numeric($inactiveMem) &&
is_numeric($laundryMem) &&
is_numeric($freeMem)) {
$usedMem = $totalMem - ($inactiveMem + $laundryMem + $freeMem);
$memUsage = round(($usedMem * 100) / $totalMem, 0);
}
}
return $memUsage;
}

/* Calculates non-idle CPU time and returns as a percentage */
function cpu_usage() {
function lcdproc_cpu_usage() {
$duration = 250000;
$diff = array('user', 'nice', 'sys', 'intr', 'idle');
$cpuTicks = array_combine($diff, explode(" ", get_single_sysctl("kern.cp_time")));
Expand Down Expand Up @@ -118,11 +77,11 @@ function get_loadavg_stats() {
return ($count >= 3) ? "{$temp[$count - 3]} {$temp[$count - 2]} {$temp[$count - 1]}" : "Not available";
}

function get_mbuf_stats() {
exec("/usr/bin/netstat -mb | /usr/bin/grep \"mbufs in use\" | /usr/bin/awk '{ print $1 }' | /usr/bin/cut -d\"/\" -f1", $mbufs_inuse);
exec("/usr/bin/netstat -mb | /usr/bin/grep \"mbufs in use\" | /usr/bin/awk '{ print $1 }' | /usr/bin/cut -d\"/\" -f3", $mbufs_total);
$status = "{$mbufs_inuse[0]} \/ {$mbufs_total[0]}";
return($status);
function lcdproc_get_mbuf_stats() {
$mbuf = "";
$mbufpercent = "";
get_mbuf($mbuf, $mbufpercent);
return($mbuf);
}

function get_version() {
Expand Down Expand Up @@ -1045,7 +1004,7 @@ function loop_status($lcd) {
/* prepare the summary data */
if ($lcdpanel_height >= "4") {
$summary_states = explode("/", get_pfstate());
$lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]);
$lcd_summary_data = sprintf("%02d%% %02d%% %6d", lcdproc_cpu_usage(), mem_usage(), $summary_states[0]);
if ($lcdpanel_width > "16") {
/* Include the CPU frequency as a percentage */
$maxfreq = get_cpu_maxfrequency();
Expand Down Expand Up @@ -1089,7 +1048,7 @@ function loop_status($lcd) {
$led_output_value = $led_output_value + pow(2, 5);
}
/* LED 3: CPU Usage */
if (cpu_usage() > 50) {
if (lcdproc_cpu_usage() > 50) {
$led_output_value = $led_output_value + pow(2, 6);
} else {
$led_output_value = $led_output_value + pow(2, 2);
Expand Down Expand Up @@ -1138,7 +1097,7 @@ function loop_status($lcd) {
$lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$hostname}\"";
break;
case "scr_system":
$processor = cpu_usage();
$processor = lcdproc_cpu_usage();
$memory = mem_usage();
$lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"CPU {$processor}%, Mem {$memory}%\"";
break;
Expand Down Expand Up @@ -1167,7 +1126,7 @@ function loop_status($lcd) {
$lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$interfaces}\"";
break;
case "scr_mbuf":
$mbufstats = get_mbuf_stats();
$mbufstats = lcdproc_get_mbuf_stats();
$lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$mbufstats}\"";
break;
case "scr_cpufrequency":
Expand Down
Expand Up @@ -175,7 +175,7 @@
'MD8800' => 'MD8800',
'ms6931' => 'ms6931',
'mtc_s16209x' => 'mtc_s16209x',
'MtxOrb' => 'Matrix Orbital',
'MtxOrb' => 'Matrix Orbital and Compatible',
'nexcom' => 'nexcom (x86 only)',
'NoritakeVFD' => 'NoritakeVFD',
'picolcd' => 'picolcd',
Expand Down Expand Up @@ -256,7 +256,8 @@
'Select the Matrix Orbital display type.%1$s' .
'Some old firmware versions of Matrix Orbital modules do not support an adjustable backlight' .
'but only can switch the backlight on/off. If you own such a module and experience randomly' .
'appearing block characters and backlight cannot be switched on or off, uncheck the adjustable backlight option.'
'appearing block characters and backlight cannot be switched on or off, uncheck the adjustable backlight option.',
'<br/>'
);
$section->add($subsection);
?>
Expand Down

0 comments on commit 07d37ba

Please sign in to comment.