From c8a167adb3a9fa500f74b586853aca8ea2c82c4c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 27 Sep 2021 16:44:21 +0200 Subject: [statistics] Hints --- modules-available/statistics/api.inc.php | 2 + .../statistics/inc/hardwareparser.inc.php | 36 +++++++++++++----- .../statistics/inc/hardwarequery.inc.php | 1 + modules-available/statistics/install.inc.php | 11 +++++- modules-available/statistics/page.inc.php | 6 ++- modules-available/statistics/pages/hints.inc.php | 41 ++++++++++++++++++++ .../templates/hints-ram-underclocked.html | 44 ++++++++++++++++++++++ .../statistics/templates/hints-ram-upgrade.html | 6 +-- 8 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 modules-available/statistics/templates/hints-ram-underclocked.html 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 @@ $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 @@ -9,6 +9,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'); @@ -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 @@ +

{{lang_ramUnderclocked}}

+ +

{{lang_ramUnderclockedText}}

+ + + + + + + + + + + + + + {{#list}} + + + + + + + + + {{/list}} + +
{{lang_machine}}{{lang_type}}{lang_speedCurrent}}{{lang_speedDesign}}{{lang_manufacturer}}{{lang_serialNumber}}
+ + {{hostname}}{{^hostname}}{{clientip}}{{/hostname}} + +
{{machineuuid}}
+
+ {{Type}} {{Form Factor}} +
{{Size}}
+
+ {{Configured Memory Speed}} + + {{Speed}} + + {{Manufacturer}} + + {{Serial Number}} +
\ 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 @@ - - - + + + -- cgit v1.2.3-55-g7522
{{lang_machine}}{{lang_installedCountMax}}{{lang_ramSizeCurrentMax}}