diff options
author | Simon Rettberg | 2021-09-24 16:42:50 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-09-24 16:42:50 +0200 |
commit | 755cab15d44d5a4e15a9ff0302861dc686e47b57 (patch) | |
tree | 9a3c4acd97fe9ad4bc3e4523e75d7d759010f3a2 /modules-available | |
parent | [statistics/passthrough] WIP (diff) | |
download | slx-admin-755cab15d44d5a4e15a9ff0302861dc686e47b57.tar.gz slx-admin-755cab15d44d5a4e15a9ff0302861dc686e47b57.tar.xz slx-admin-755cab15d44d5a4e15a9ff0302861dc686e47b57.zip |
[statistics/passthrough] WIP
Diffstat (limited to 'modules-available')
7 files changed, 99 insertions, 15 deletions
diff --git a/modules-available/passthrough/page.inc.php b/modules-available/passthrough/page.inc.php index 0911550c..3ab0696e 100644 --- a/modules-available/passthrough/page.inc.php +++ b/modules-available/passthrough/page.inc.php @@ -66,10 +66,10 @@ class Page_Passthrough extends Page private function showHardwareList() { $q = new HardwareQuery(HardwareInfo::PCI_DEVICE, null, false); - $q->addColumn(true, 'vendor'); - $q->addColumn(true, 'device'); - $q->addColumn(true, 'class'); - $q->addColumn(true, '@PASSTHROUGH'); + $q->addGlobalColumn('vendor'); + $q->addGlobalColumn('device'); + $q->addGlobalColumn('class'); + $q->addGlobalColumn('@PASSTHROUGH'); $rows = []; foreach ($q->query('shw.hwid') as $row) { $row['ptlist'] = Passthrough::getGroupDropdown($row); diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index b06d4503..ccc6bbd5 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -6,7 +6,7 @@ if (Request::any('action') === 'test' && isLocalExecution()) { $x = new HardwareQuery(HardwareInfo::PCI_DEVICE); //$x->addCompare(false, 'Memory Slot Occupied', '>=', true, 'Memory Slot Count'); $x->addWhere(true, 'vendor', '=', '8086'); - $x->addColumn(true, 'device'); + $x->addGlobalColumn('device'); $res = $x->query(); foreach ($res as $row) { error_log(json_encode($row)); diff --git a/modules-available/statistics/inc/hardwareinfo.inc.php b/modules-available/statistics/inc/hardwareinfo.inc.php index 5f1a4372..6a6c74cd 100644 --- a/modules-available/statistics/inc/hardwareinfo.inc.php +++ b/modules-available/statistics/inc/hardwareinfo.inc.php @@ -42,9 +42,9 @@ class HardwareInfo $hw = new HardwareQuery(self::PCI_DEVICE, $best['machineuuid'], true); // TODO: Get list of enabled pass through groups for this client's location $hw->addWhere(true, '@PASSTHROUGH', 'IN', ['GPU', 'GVT']); - $hw->addColumn(true, 'vendor'); - $hw->addColumn(true, 'device'); - $hw->addColumn(false, 'slot'); + $hw->addGlobalColumn('vendor'); + $hw->addGlobalColumn('device'); + $hw->addLocalColumn('slot'); $res = $hw->query(); $passthrough = []; $slots = []; @@ -67,8 +67,8 @@ class HardwareInfo error_log('Querying slot ' . $slot); $hw = new HardwareQuery(self::PCI_DEVICE, $best['machineuuid'], true); $hw->addWhere(false, 'slot', 'LIKE', $slot . '.%'); - $hw->addColumn(true, 'vendor'); - $hw->addColumn(true, 'device'); + $hw->addGlobalColumn('vendor'); + $hw->addGlobalColumn('device'); foreach ($hw->query() as $row) { $passthrough[$row['vendor'] . ':' . $row['device']] = 1; error_log('Extra PT: ' . $row['vendor'] . ':' . $row['device']); diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php index 5ba1e3dd..55ebbbcc 100644 --- a/modules-available/statistics/inc/hardwareparser.inc.php +++ b/modules-available/statistics/inc/hardwareparser.inc.php @@ -630,10 +630,12 @@ class HardwareParser $globalMainboardExtra['Memory Slot Count'] += $mem['Number Of Devices']; } if (isset($mem['Maximum Capacity'])) { - $globalMainboardExtra['Memory Maximum Capacity'] += self::convertSize($mem['Maximum Capacity'], 'M', false); + $globalMainboardExtra['Memory Maximum Capacity'] + += self::convertSize($mem['Maximum Capacity'], 'M', false); } } - $globalMainboardExtra['Memory Maximum Capacity'] = self::convertSize($globalMainboardExtra['Memory Maximum Capacity'] . ' MB'); + $globalMainboardExtra['Memory Maximum Capacity'] + = self::convertSize($globalMainboardExtra['Memory Maximum Capacity'] . ' MB', 'G'); // BIOS section - need to cross-match this with mainboard or system model, as it doesn't have a meaningful // identifier on its own $bios = self::prepareDmiProperties(self::getDmiHandles($data, 0)[0]); @@ -651,8 +653,14 @@ class HardwareParser } } // Using the general helper function - $ramModCount = self::updateHwTypeFromDmi($uuid, $data, 17, HardwareInfo::RAM_MODULE, function (array $flat): bool { - return self::convertSize(($flat['Size'] ?? 0), '', false) > 65 * 1024 * 1024; + $capa = 0; + $ramModCount = self::updateHwTypeFromDmi($uuid, $data, 17, HardwareInfo::RAM_MODULE, function (array $flat) use (&$capa): bool { + $size = self::convertSize(($flat['Size'] ?? 0), '', false); + if ($size > 65 * 1024 * 1024) { + $capa += $size; + return true; + } + return false; }, ['Locator'], ['Data Width', @@ -669,6 +677,7 @@ class HardwareParser ); // Fake RAM slots used/total into this $localMainboardExtra['Memory Slot Occupied'] = $ramModCount; + $localMainboardExtra['Memory Installed Capacity'] = self::convertSize($capa, 'G', true); self::updateHwTypeFromDmi($uuid, $data, 2, HardwareInfo::MAINBOARD, ['Manufacturer', 'Product Name'], [], ['Manufacturer', 'Product Name', 'Type', 'Version'], diff --git a/modules-available/statistics/inc/hardwarequery.inc.php b/modules-available/statistics/inc/hardwarequery.inc.php index c7ecb35e..f0a73d27 100644 --- a/modules-available/statistics/inc/hardwarequery.inc.php +++ b/modules-available/statistics/inc/hardwarequery.inc.php @@ -13,7 +13,7 @@ class HardwareQuery * @param string $type type form HardwareInfo * @param ?string $uuid */ - public function __construct($type, $uuid = null, $connectedOnly = true) + public function __construct(string $type, $uuid = null, $connectedOnly = true) { if ($connectedOnly) { $this->joins['mxhw_join'] = "INNER JOIN machine_x_hw mxhw ON (mxhw.hwid = shw.hwid AND mxhw.disconnecttime = 0)"; @@ -120,6 +120,14 @@ class HardwareQuery $this->columns[$prop] = "$tid.`value` AS `$prop`"; } + public function addMachineColumn(string $column) + { + if (isset($this->columns[$column])) + return; + $this->joins['machine'] = 'INNER JOIN machine m USING (machineuuid)'; + $this->columns[$column] = "m.$column"; + } + /** * @return false|PDOStatement */ diff --git a/modules-available/statistics/pages/hints.inc.php b/modules-available/statistics/pages/hints.inc.php new file mode 100644 index 00000000..d5e7487b --- /dev/null +++ b/modules-available/statistics/pages/hints.inc.php @@ -0,0 +1,36 @@ +<?php + +class SubPage +{ + + public static function doPreprocess() + { + + } + + public static function doRender() + { + $q = new HardwareQuery(HardwareInfo::MAINBOARD); + $q->addLocalColumn('Memory Slot Occupied'); + $q->addGlobalColumn('Memory Slot Count'); + $q->addGlobalColumn('Memory Maximum Capacity'); + $q->addMachineColumn('clientip'); + $q->addMachineColumn('hostname'); + $q->addWhere(false, 'Memory Installed Capacity', '<', 8 * 1024 * 1024 * 1024); + $list = []; + foreach ($q->query() as $row) { + if (HardwareParser::convertSize($row['Memory Installed Capacity'], 'M', false) + >= HardwareParser::convertSize($row['Memory Maximum Capacity'], 'M', false)) { + $row['size_class'] = 'danger'; + $list[] = $row; + } elseif ($row['Memory Slot Occupied'] < $row['Memory Slot Count']) { + $row['count_class'] = 'success'; + array_unshift($list, $row); + } else { + $list[] = $row; + } + } + Render::addTemplate('hints-ram-upgrade', ['list' => $list]); + } + +}
\ No newline at end of file diff --git a/modules-available/statistics/templates/hints-ram-upgrade.html b/modules-available/statistics/templates/hints-ram-upgrade.html new file mode 100644 index 00000000..8b7a3be9 --- /dev/null +++ b/modules-available/statistics/templates/hints-ram-upgrade.html @@ -0,0 +1,31 @@ +<h2>{{lang_ramUpgrade}}</h2> + +<p>{{lang_ramUpgradeText}}</p> + +<table class="table"> + <thead> + <tr> + <th></th> + <th></th> + <th></th> + </tr> + </thead> + <tbody> + {{#list}} + <tr> + <td> + <a class="slx-bold" href="?do=statistics&uuid={{machineuuid}}"> + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} + </a> + <div class="small">{{machineuuid}}</div> + </td> + <td class="{{count_class}}"> + {{Memory Slot Occupied}} / {{Memory Slot Count}} + </td> + <td class="{{size_class}}"> + {{Memory Installed Capacity}} / {{Memory Maximum Capacity}} + </td> + </tr> + {{/list}} + </tbody> +</table>
\ No newline at end of file |