From 6e183c043091cf4a6c261b57fbfd9595cf76e93e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 27 Oct 2022 16:16:36 +0200 Subject: [statistics] Add machine state icon to hints tables --- .../statistics/inc/statisticsstyling.inc.php | 20 ++++++++++++++++++++ modules-available/statistics/pages/hints.inc.php | 10 ++++++++++ .../statistics/templates/hints-hdd-grow.html | 2 ++ .../statistics/templates/hints-nic-speed.html | 1 + .../statistics/templates/hints-ram-underclocked.html | 1 + .../statistics/templates/hints-ram-upgrade.html | 1 + 6 files changed, 35 insertions(+) (limited to 'modules-available') diff --git a/modules-available/statistics/inc/statisticsstyling.inc.php b/modules-available/statistics/inc/statisticsstyling.inc.php index 9d0bb8cc..1843fe30 100644 --- a/modules-available/statistics/inc/statisticsstyling.inc.php +++ b/modules-available/statistics/inc/statisticsstyling.inc.php @@ -39,4 +39,24 @@ class StatisticsStyling return ''; } + /** + * Take a machine state enum value, return a matching glyphicon class. + * @param string $state State value (OFFLINE, IDLE, ...) + */ + public static function machineStateToIcon(string $state): string + { + switch ($state) { + case 'OFFLINE': + return 'glyphicon-off'; + case 'IDLE': + return 'glyphicon-ok green'; + case 'OCCUPIED': + return 'glyphicon-user red'; + case 'STANDBY': + return 'glyphicon-off green'; + default: + return 'glyphicon-question-sign'; + } + } + } \ No newline at end of file diff --git a/modules-available/statistics/pages/hints.inc.php b/modules-available/statistics/pages/hints.inc.php index 9b4fe568..dc789e9f 100644 --- a/modules-available/statistics/pages/hints.inc.php +++ b/modules-available/statistics/pages/hints.inc.php @@ -48,6 +48,7 @@ class SubPage $q->addGlobalColumn('Memory Maximum Capacity'); $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); + $q->addMachineColumn('state'); $q->addLocalColumn('Memory Installed Capacity')->addCondition('<', 8 * 1024 * 1024 * 1024); $list = []; foreach ($q->query() as $row) { @@ -60,6 +61,7 @@ class SubPage if ($row['Memory Slot Occupied'] >= $row['Memory Slot Count']) { $row['count_class'] = 'warning'; } + $row['icon'] = StatisticsStyling::machineStateToIcon($row['state']); $list[] = $row; } if (empty($list)) @@ -87,6 +89,7 @@ class SubPage $q->addLocalColumn('Serial Number'); $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); + $q->addMachineColumn('state'); $col = $q->addGlobalColumn('Speed'); $col->addCondition('>', $q->addLocalColumn('Configured Memory Speed')); $list = []; @@ -95,6 +98,7 @@ class SubPage // Cast as these have a MT/s suffic, triggering a PHP notice about malformed numbers if ((int)$row['Configured Memory Speed'] + 33 >= (int)$row['Speed']) continue; + $row['icon'] = StatisticsStyling::machineStateToIcon($row['state']); $list[] = $row; } if (empty($list)) @@ -119,9 +123,11 @@ class SubPage $q->addMachineColumn('hostname'); $q->addLocalColumn('unused')->addCondition('>', 2000000000); // 2 GB $q->addMachineWhere('id44mb', '<', 20000); // 20 GB + $q->addMachineColumn('state'); foreach ($q->query() as $row) { $row['unused_s'] = Util::readableFileSize($row['unused']); $row['id44mb_s'] = Util::readableFileSize($row['id44mb'], -1, 2); + $row['icon'] = StatisticsStyling::machineStateToIcon($row['state']); $id44[] = $row; } // ID45 @@ -134,12 +140,14 @@ class SubPage $q->addLocalColumn('unused')->addCondition('>', 50000000000); // 50 GB $q->addMachineWhere('id44mb', '>', 20000); // 20 GB $q->addMachineWhere('id45mb', '<', 20000); // 20 GB + $q->addMachineColumn('state'); // Only suggest SSD based systems, caching on spinning rust is usually slower than GBit $q->addGlobalColumn('rotation_rate')->addCondition('=', 0); foreach ($q->query() as $row) { $row['unused_s'] = Util::readableFileSize($row['unused']); $row['id44mb_s'] = Util::readableFileSize($row['id44mb'], -1, 2); $row['id45mb_s'] = Util::readableFileSize($row['id45mb'], -1, 2); + $row['icon'] = StatisticsStyling::machineStateToIcon($row['state']); $id45[] = $row; } if (empty($id44) && empty($id45)) @@ -161,12 +169,14 @@ class SubPage } $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); + $q->addMachineColumn('state'); $q->addLocalColumn('nic-speed')->addCondition('<', 1000); $q->addLocalColumn('nic-duplex'); foreach ($q->query() as $row) { if ($row['nic-speed'] == 0) { $row['nic-speed'] = '???'; } + $row['icon'] = StatisticsStyling::machineStateToIcon($row['state']); $list[] = $row; } if (empty($list)) diff --git a/modules-available/statistics/templates/hints-hdd-grow.html b/modules-available/statistics/templates/hints-hdd-grow.html index 26e4f73f..b7c5bff4 100644 --- a/modules-available/statistics/templates/hints-hdd-grow.html +++ b/modules-available/statistics/templates/hints-hdd-grow.html @@ -14,6 +14,7 @@ {{#id44}} + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} @@ -45,6 +46,7 @@ {{#id45}} + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} diff --git a/modules-available/statistics/templates/hints-nic-speed.html b/modules-available/statistics/templates/hints-nic-speed.html index c26364e6..963213cd 100644 --- a/modules-available/statistics/templates/hints-nic-speed.html +++ b/modules-available/statistics/templates/hints-nic-speed.html @@ -14,6 +14,7 @@ {{#list}} + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} diff --git a/modules-available/statistics/templates/hints-ram-underclocked.html b/modules-available/statistics/templates/hints-ram-underclocked.html index a46f02d9..35bdd857 100644 --- a/modules-available/statistics/templates/hints-ram-underclocked.html +++ b/modules-available/statistics/templates/hints-ram-underclocked.html @@ -18,6 +18,7 @@ {{#list}} + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} diff --git a/modules-available/statistics/templates/hints-ram-upgrade.html b/modules-available/statistics/templates/hints-ram-upgrade.html index be0d2532..7b60d419 100644 --- a/modules-available/statistics/templates/hints-ram-upgrade.html +++ b/modules-available/statistics/templates/hints-ram-upgrade.html @@ -14,6 +14,7 @@ {{#list}} + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} -- cgit v1.2.3-55-g7522