diff options
author | Simon Rettberg | 2021-09-27 16:44:21 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-09-27 16:44:21 +0200 |
commit | c8a167adb3a9fa500f74b586853aca8ea2c82c4c (patch) | |
tree | a41f76f4764380829e794cdedb3a145fde6e9a4f | |
parent | [statistics/passthrough] WIP (diff) | |
download | slx-admin-c8a167adb3a9fa500f74b586853aca8ea2c82c4c.tar.gz slx-admin-c8a167adb3a9fa500f74b586853aca8ea2c82c4c.tar.xz slx-admin-c8a167adb3a9fa500f74b586853aca8ea2c82c4c.zip |
[statistics] Hints
8 files changed, 132 insertions, 15 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index ccc6bbd5..52dbe284 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -1,6 +1,7 @@ <?php if (Request::any('action') === 'test' && isLocalExecution()) { + /* error_log(HardwareInfo::getKclModifications()); exit; $x = new HardwareQuery(HardwareInfo::PCI_DEVICE); @@ -12,6 +13,7 @@ if (Request::any('action') === 'test' && isLocalExecution()) { error_log(json_encode($row)); } exit; + */ HardwareParser::parseMachine('0A5D9E23-80F4-9C43-912C-96D80AE7E80B', file_get_contents('/tmp/bla.json')); echo 'Kweries: ' . Database::getQueryCount(); diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php index 55ebbbcc..15534749 100644 --- a/modules-available/statistics/inc/hardwareparser.inc.php +++ b/modules-available/statistics/inc/hardwareparser.inc.php @@ -444,8 +444,8 @@ class HardwareParser return (int)($out[1] * self::SI_LOOKUP[strtoupper($out[2])]); } // Count, size (unitless) - if (is_numeric($val) && preg_match('/^[0-9]+$/', $val) - && preg_match('/used|occupied|count|number|size/', $key)) { + if (is_numeric($val) && preg_match('/^-?[0-9]+$/', $val) + && preg_match('/used|occupied|count|number|size|temperature/', $key)) { return (int)$val; } // Date @@ -734,6 +734,7 @@ class HardwareParser self::markDisconnected($uuid, HardwareInfo::PCI_DEVICE, $pciHwIds); // ---- Disks ------------------------------------0Y3R3K $hddHwIds = []; + $id44 = $id45 = 0; foreach (($data['drives'] ?? []) as $dev) { if (empty($dev['readlink'])) continue; @@ -750,11 +751,12 @@ class HardwareParser if (!isset($smart['rotation_rate']) && isset($lsblk['rota']) && !$lsblk['rota']) { $smart['rotation_rate'] = 0; } + $size = $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown'; $hwid = self::writeGlobalHardwareData(HardwareInfo::HDD, [ // Try to use the model name as the unique identifier 'model' => $smart['model_name'] ?? $lsblk['model'] ?? 'unknown', // Append device size as some kind of fallback, in case model is unknown - 'size' => $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown', + 'size' => $size, 'physical_block_size' => $smart['physical_block_size'] ?? $lsblk['phy-sec'] ?? 0, 'logical_block_size' => $smart['logical_block_size'] ?? $lsblk['log-sec'] ?? 0, ] + self::propsFromArray($smart, @@ -792,6 +794,7 @@ class HardwareParser }, ARRAY_FILTER_USE_BOTH); } // Partitions - find special ones + $used = 0; if (isset($dev['sfdisk']['partitiontable'])) { $table['partition_table'] = $dev['sfdisk']['partitiontable']['label'] ?? 'none'; switch ($dev['sfdisk']['partitiontable']['unit'] ?? 'sectors') { @@ -806,6 +809,13 @@ class HardwareParser } $i = 0; foreach (($dev['sfdisk']['partitiontable']['partitions'] ?? []) as $part) { + if (!isset($part['size'])) + continue; + $type = hexdec($part['type'] ?? '0'); + if ($type === 0x0 || $type === 0x5 || $type === 0xf || $type === 0x15 || $type === 0x1f + || $type === 0x85 || $type === 0xc5 || $type == 0xcf) + continue; // Extended partition, ignore + $used += $part['size'] * $fac; $id = 'part_' . $i . '_'; foreach (['start', 'size', 'type', 'uuid', 'name'] as $item) { if (!isset($part[$item])) @@ -822,19 +832,23 @@ class HardwareParser if ($type == '44' || strtolower($type) === '87f86132-ff94-4987-b250-444444444444' || $name === 'OpenSLX-ID44') { $table[$id . 'slxtype'] = '44'; + $id44 += $part['size'] * $fac; } elseif ($type == '45' || strtolower($type) === '87f86132-ff94-4987-b250-454545454545' || $name === 'OpenSLX-ID45') { $table[$id . 'slxtype'] = '45'; + $id45 += $part['size'] * $fac; } // ++$i; } } + $table['unused'] = $size - $used; + $table += self::propsFromArray($smart + ($lsblk ?? []), + 'serial_number', 'firmware_version', + 'interface_speed//current//string', + 'smart_status//passed', 'temperature//current', 'temperature//min', 'temperature//max'); $mappingId = self::writeLocalHardwareData($uuid, $hwid, $dev['readlink'], - self::propsFromArray($smart + ($lsblk ?? []), - 'serial_number', 'firmware_version', - 'interface_speed//current//string', - 'smart_status//passed', 'temperature//current', 'temperature//min', 'temperature//max') + $table); + $table); // Delete old partition and smart attribute entries Database::exec("DELETE FROM machine_x_hw_prop WHERE machinehwid = :id AND prop NOT IN (:keep) AND prop NOT LIKE '@%'", [ @@ -847,8 +861,12 @@ class HardwareParser self::markDisconnected($uuid, HardwareInfo::HDD, $hddHwIds); // // Mark parse date - Database::exec("UPDATE machine SET dataparsetime = UNIX_TIMESTAMP() WHERE machineuuid = :uuid", - ['uuid' => $uuid]); + Database::exec("UPDATE machine SET dataparsetime = UNIX_TIMESTAMP(), id44mb = :id44, id45mb = :id45 + WHERE machineuuid = :uuid", [ + 'uuid' => $uuid, + 'id44' => round($id44 / (1024 * 1024)), + 'id45' => round($id45 / (1024 * 1024)), + ]); } /** diff --git a/modules-available/statistics/inc/hardwarequery.inc.php b/modules-available/statistics/inc/hardwarequery.inc.php index f0a73d27..6b5662d4 100644 --- a/modules-available/statistics/inc/hardwarequery.inc.php +++ b/modules-available/statistics/inc/hardwarequery.inc.php @@ -96,6 +96,7 @@ class HardwareQuery $this->args[$pid1] = $prop1; $this->args[$pid2] = $prop2; $this->columns[$prop1] = "$tid1.`value` AS `$prop1`"; + $this->columns[$prop2] = "$tid2.`value` AS `$prop2`"; } public function addGlobalColumn(string $prop) diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php index 5856c81e..1b664d04 100644 --- a/modules-available/statistics/install.inc.php +++ b/modules-available/statistics/install.inc.php @@ -40,6 +40,7 @@ $res[] = tableCreate('machine', " `cpumodel` varchar(120) NOT NULL, `systemmodel` varchar(120) NOT NULL DEFAULT '', `id44mb` int(10) unsigned NOT NULL, + `id45mb` int(10) unsigned NOT NULL, `badsectors` int(10) unsigned NOT NULL, `data` mediumblob NOT NULL, `dataparsetime` int(10) unsigned NOT NULL DEFAULT 0, @@ -339,7 +340,15 @@ if (!tableHasColumn('machine', 'dataparsetime')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `dataparsetime` int(10) unsigned NOT NULL DEFAULT '0' AFTER `data`"); if ($ret === false) { - finalResponse(UPDATE_FAILED, 'Adding mem-stat columns to machine table failed: ' . Database::lastError()); + finalResponse(UPDATE_FAILED, 'Adding dateparsetime column to machine table failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} +if (!tableHasColumn('machine', 'id45mb')) { + $ret = Database::exec("ALTER TABLE `machine` + ADD COLUMN `id45mb` int(10) unsigned NOT NULL AFTER `id44mb`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding id45mb column to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index baddd093..04d9a515 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -24,10 +24,12 @@ class Page_Statistics extends Page /* Dictionary::translate('submenu_projectors'); Dictionary::translate('submenu_replace'); + Dictionary::translate('submenu_hints'); */ - foreach (['projectors', 'replace'] as $section) { - Dashboard::addSubmenu('?do=statistics&show=' . $section, Dictionary::translate('submenu_' . $section, true)); + foreach (['projectors', 'replace', 'hints'] as $section) { + Dashboard::addSubmenu('?do=statistics&show=' . $section, + Dictionary::translate('submenu_' . $section, true)); } $this->show = Request::any('show', false, 'string'); diff --git a/modules-available/statistics/pages/hints.inc.php b/modules-available/statistics/pages/hints.inc.php index d5e7487b..5c6acfbb 100644 --- a/modules-available/statistics/pages/hints.inc.php +++ b/modules-available/statistics/pages/hints.inc.php @@ -10,6 +10,13 @@ class SubPage public static function doRender() { + self::showMemoryUpgrade(); + self::showMemorySlow(); + self::showUnusedSpace(); + } + + private static function showMemoryUpgrade() + { $q = new HardwareQuery(HardwareInfo::MAINBOARD); $q->addLocalColumn('Memory Slot Occupied'); $q->addGlobalColumn('Memory Slot Count'); @@ -33,4 +40,38 @@ class SubPage Render::addTemplate('hints-ram-upgrade', ['list' => $list]); } + private static function showMemorySlow() + { + $q = new HardwareQuery(HardwareInfo::RAM_MODULE); + $q->addLocalColumn('Locator'); + $q->addLocalColumn('Bank Locator'); + $q->addGlobalColumn('Form Factor'); + $q->addGlobalColumn('Type'); + $q->addGlobalColumn('Size'); + $q->addGlobalColumn('Manufacturer'); + $q->addLocalColumn('Serial Number'); + $q->addMachineColumn('clientip'); + $q->addMachineColumn('hostname'); + $q->addCompare(true, 'Speed', '>', false, 'Configured Memory Speed'); + $list = $q->query()->fetchAll(); + Render::addTemplate('hints-ram-underclocked', ['list' => $list]); + } + + private static function showUnusedSpace() + { + $q = new HardwareQuery(HardwareInfo::HDD); + $q->addWhere(false, 'unused', '>', 2000000000); // 2 GB + $q->addMachineWhere('id44mb', '<', 20000); // 20 GB + $id44 = $q->query()->fetchAll(); + $q = new HardwareQuery(HardwareInfo::HDD); + $q->addWhere(false, 'unused', '>', 25000000000); // 25 GB + $q->addMachineWhere('id44mb', '>', 20000); // 20 GB + $q->addMachineWhere('id45mb', '<', 20000); // 20 GB + $id45 = $q->query()->fetchAll(); + Render::addTemplate('hints-hdd-grow', [ + 'id44' => $id44, + 'id45' => $id45, + ]); + } + }
\ No newline at end of file diff --git a/modules-available/statistics/templates/hints-ram-underclocked.html b/modules-available/statistics/templates/hints-ram-underclocked.html new file mode 100644 index 00000000..e1f19c4f --- /dev/null +++ b/modules-available/statistics/templates/hints-ram-underclocked.html @@ -0,0 +1,44 @@ +<h2>{{lang_ramUnderclocked}}</h2> + +<p>{{lang_ramUnderclockedText}}</p> + +<table class="table"> + <thead> + <tr> + <th>{{lang_machine}}</th> + <th>{{lang_type}}</th> + <th>{lang_speedCurrent}}</th> + <th>{{lang_speedDesign}}</th> + <th>{{lang_manufacturer}}</th> + <th>{{lang_serialNumber}}</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> + {{Type}} {{Form Factor}} + <div>{{Size}}</div> + </td> + <td> + {{Configured Memory Speed}} + </td> + <td> + {{Speed}} + </td> + <td> + {{Manufacturer}} + </td> + <td> + {{Serial Number}} + </td> + </tr> + {{/list}} + </tbody> +</table>
\ 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 index 8b7a3be9..be0d2532 100644 --- a/modules-available/statistics/templates/hints-ram-upgrade.html +++ b/modules-available/statistics/templates/hints-ram-upgrade.html @@ -5,9 +5,9 @@ <table class="table"> <thead> <tr> - <th></th> - <th></th> - <th></th> + <th>{{lang_machine}}</th> + <th>{{lang_installedCountMax}}</th> + <th>{{lang_ramSizeCurrentMax}}</th> </tr> </thead> <tbody> |