From 28c58465da6dabac239d6028a99b95ad49210c5d Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 2 Dec 2023 12:56:52 +0100 Subject: [PATCH] Dashboard: add NVME power indicator --- emhttp/plugins/dynamix/DashStats.page | 6 +++--- emhttp/plugins/dynamix/include/Wrappers.php | 3 +++ emhttp/plugins/dynamix/nchan/device_list | 8 ++++---- emhttp/plugins/dynamix/nchan/update_2 | 13 +++++++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index 4c0b525d0..22484fafa 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -562,7 +562,7 @@ if (!$group) { -_(Device)__(Status)__(Temp)__(SMART)__(Utilization)_ +_(Device)__(Status)__(Temp)_ / _(Power)__(SMART)__(Utilization)_ @@ -573,7 +573,7 @@ if (!$group) { -_(Device)__(Status)__(Temp)__(SMART)__(Utilization)_ +_(Device)__(Status)__(Temp)_ / _(Power)__(SMART)__(Utilization)_ @@ -584,7 +584,7 @@ if (!$group) { -_(Device)__(Status)__(Temp)__(SMART)__(Utilization)_ +_(Device)__(Status)__(Temp)_ / _(Power)__(SMART)__(Utilization)_ diff --git a/emhttp/plugins/dynamix/include/Wrappers.php b/emhttp/plugins/dynamix/include/Wrappers.php index 272553b5f..03284d3fd 100644 --- a/emhttp/plugins/dynamix/include/Wrappers.php +++ b/emhttp/plugins/dynamix/include/Wrappers.php @@ -132,6 +132,9 @@ function get_nvme_info($device, $info) { return exec("nvme id-ctrl /dev/$device | grep -Pom1 '^cctemp +: \K\d+'")-273; case 'wctemp': return exec("nvme id-ctrl /dev/$device | grep -Pom1 '^wctemp +: \K\d+'")-273; + case 'state': + $state = hexdec(exec("nvme get-feature /dev/$device -f2 | grep -Pom1 'value:\K0x\d+'")); + return exec("nvme id-ctrl /dev/$device | grep -Pom1 '^ps +$state : \S+ \K\S+'"); case 'power': $state = hexdec(exec("nvme get-feature /dev/$device -f2 | grep -Pom1 'value:\K0x\d+'")); return exec("smartctl -c /dev/$device | grep -Pom1 '^ *$state [+-] +\K[^W]+'"); diff --git a/emhttp/plugins/dynamix/nchan/device_list b/emhttp/plugins/dynamix/nchan/device_list index 1388fb41c..f16136ac2 100755 --- a/emhttp/plugins/dynamix/nchan/device_list +++ b/emhttp/plugins/dynamix/nchan/device_list @@ -38,7 +38,7 @@ function initSum() { function model($id) { return substr($id,0,strrpos($id,'_')); } -function power($power) { +function my_power($power) { global $display; $number = _var($display,'number','.,'); return $power ? ' / '.number_format($power,2,$number[0]).' W' : ''; @@ -215,7 +215,7 @@ function array_offline(&$disk, $pool='') { case 'DISK_NEW': $echo[] = "".device_info($disk,false).""; $echo[] = "".assignment($disk).""; - $echo[] = "".my_temp(_var($disk,'temp','*')).power($disk['power']).""; + $echo[] = "".my_temp(_var($disk,'temp','*')).my_power($disk['power']).""; if ($warning) { $echo[] = "$warning"; } else { @@ -284,7 +284,7 @@ function array_online(&$disk, $fstype='') { default: $echo[] = "".device_info($disk,true).""; $echo[] = "".device_desc($disk).""; - $echo[] = "".my_temp(_var($disk,'temp','*')).power($disk['power']).""; + $echo[] = "".my_temp(_var($disk,'temp','*')).my_power($disk['power']).""; $echo[] = "".my_diskio($data[0])."".my_number(_var($disk,'numReads',0)).""; $echo[] = "".my_diskio($data[1])."".my_number(_var($disk,'numWrites',0)).""; $echo[] = "".my_number(_var($disk,'numErrors',0)).""; @@ -305,7 +305,7 @@ function show_totals($text,$array,$name) { $echo[] = ""; $echo[] = "$help1$help2"; $echo[] = "$text"; - $echo[] = "".($sum['count']>0 ? my_temp(round($sum['temp']/$sum['count'],1)) : '*').power($sum['power']).""; + $echo[] = "".($sum['count']>0 ? my_temp(round($sum['temp']/$sum['count'],1)) : '*').my_power($sum['power']).""; $echo[] = "".my_diskio($sum['ioReads'])."".my_number($sum['numReads']).""; $echo[] = "".my_diskio($sum['ioWrites'])."".my_number($sum['numWrites']).""; $echo[] = "".my_number($sum['numErrors']).""; diff --git a/emhttp/plugins/dynamix/nchan/update_2 b/emhttp/plugins/dynamix/nchan/update_2 index d91f088f4..309b56034 100755 --- a/emhttp/plugins/dynamix/nchan/update_2 +++ b/emhttp/plugins/dynamix/nchan/update_2 @@ -30,6 +30,12 @@ require_once "$docroot/webGui/include/Translations.php"; // remember current language $locale_init = $locale; +function my_power($device, $power) { + global $display; + $number = _var($display,'number','.,'); + $state = strtr(get_nvme_info($device,'state'),['non-operational' => 'green', 'operational' => 'orange']); + return " / ".number_format($power,2,$number[0])." W"; +} function my_clock($time) { if (!$time) return _('less than a minute'); $days = floor($time/1440); @@ -156,7 +162,8 @@ function device_temp(&$disk, &$red, &$orange) { global $display; $spin = strpos(_var($disk,'color'),'blink')===false; $temp = _var($disk,'temp','*'); - [$hotNVME,$maxNVME] = _var($disk,'transport')=='nvme' ? get_nvme_info(_var($disk,'device'),'temp') : [-1,-1]; + $nvme = _var($disk,'transport')=='nvme'; + [$hotNVME,$maxNVME] = $nvme ? get_nvme_info(_var($disk,'device'),'temp') : [-1,-1]; $hot = _var($disk,'hotTemp',-1)>=0 ? $disk['hotTemp'] : ($hotNVME>=0 ? $hotNVME : (_var($disk,'rotational',1)==0 && $display['hot']>0 ? $display['hot']+$display['ssd'] : $display['hot'])); $max = _var($disk,'maxTemp',-1)>=0 ? $disk['maxTemp'] : ($maxNVME>=0 ? $maxNVME : (_var($disk,'rotational',1)==0 && $display['max']>0 ? $display['max']+$display['ssd'] : $display['max'])); $top = $display['top'] ?? 120; @@ -166,7 +173,9 @@ function device_temp(&$disk, &$red, &$orange) { } elseif (exceed($temp,$hot,$top)) { $heat = 'fire'; $color = 'orange'; $orange++; } - return ($spin && $temp>0) ? "".my_temp($temp)."".($heat ? "" : "") : "*"; + $device = _var($disk,'device'); + $power = $disk['power'] ?? ($nvme ? get_nvme_info($device,'power') : 0); + return (($spin && $temp>0) ? "".my_temp($temp)."".($heat ? "" : "") : "*").($nvme ? my_power($device, $power) : ""); } function device_smart(&$disk, &$fail, &$smart) { global $numbers,$saved;