From 19429f6dddb1403b226432cf3118be09962a1d22 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 4 Dec 2015 21:13:36 +0100 Subject: [statistics] More tweaks, add detailed memory information, show system manufacturer if known --- lang/de/templates/statistics/machine-main.json | 3 + lang/en/templates/statistics/machine-main.json | 3 + modules/statistics.inc.php | 80 +++++++++++++++++++++++++- templates/statistics/id44.html | 4 +- templates/statistics/kvmstate.html | 4 +- templates/statistics/machine-main.html | 23 +++++++- templates/statistics/memory.html | 4 +- 7 files changed, 112 insertions(+), 9 deletions(-) diff --git a/lang/de/templates/statistics/machine-main.json b/lang/de/templates/statistics/machine-main.json index 751ff8c7..a0b2182a 100644 --- a/lang/de/templates/statistics/machine-main.json +++ b/lang/de/templates/statistics/machine-main.json @@ -10,7 +10,10 @@ "lang_lastSeen": "Letzte Aktivit\u00e4t", "lang_macAddr": "MAC-Adresse", "lang_machineSummary": "Zusammenfassung", + "lang_maximumAbbrev": "Max.", + "lang_model": "Modell", "lang_ram": "Arbeitsspeicher", + "lang_ramSlots": "Speicher-Slots", "lang_sockets": "Sockel", "lang_tempPart": "Temp. Partition", "lang_uuid": "UUID", diff --git a/lang/en/templates/statistics/machine-main.json b/lang/en/templates/statistics/machine-main.json index 2aa3b9ba..40ea72f8 100644 --- a/lang/en/templates/statistics/machine-main.json +++ b/lang/en/templates/statistics/machine-main.json @@ -10,7 +10,10 @@ "lang_lastSeen": "Last activity", "lang_macAddr": "MAC address", "lang_machineSummary": "Summary", + "lang_maximumAbbrev": "max.", + "lang_model": "Model", "lang_ram": "Memory", + "lang_ramSlots": "Memory slots", "lang_sockets": "Sockets", "lang_tempPart": "Temp. partition", "lang_uuid": "UUID", diff --git a/modules/statistics.inc.php b/modules/statistics.inc.php index c8c869b9..3e829847 100644 --- a/modules/statistics.inc.php +++ b/modules/statistics.inc.php @@ -356,11 +356,14 @@ class Page_Statistics extends Page $row['hddclass'] = $this->hddColorClass($row['gbtmp']); // Parse the giant blob of data $hdds = array(); - if (preg_match_all('/##### ([^#]+) #+$(.*?)^#####/ims', $row['data'], $out, PREG_SET_ORDER)) { + if (preg_match_all('/##### ([^#]+) #+$(.*?)^#####/ims', $row['data'] . '########', $out, PREG_SET_ORDER)) { foreach ($out as $section) { if ($section[1] === 'CPU') { $this->parseCpu($row, $section[2]); } + if ($section[1] === 'dmidecode') { + $this->parseDmiDecode($row, $section[2]); + } if ($section[1] === 'Partition tables') { $this->parseHdd($hdds, $section[2]); } @@ -384,6 +387,81 @@ class Page_Statistics extends Page } } + private function parseDmiDecode(&$row, $data) + { + $lines = preg_split("/[\r\n]+/", $data); + $section = false; + $ramOk = false; + $ramForm = $ramType = $ramSpeed = $ramClockSpeed = false; + foreach ($lines as $line) { + if ($line{0} !== "\t" && $line{0} !== ' ') { + $section = $line; + $ramOk = false; + if (($ramForm || $ramType) && ($ramSpeed || $ramClockSpeed)) { + if (isset($row['ramtype']) && !$ramClockSpeed) continue; + $row['ramtype'] = $ramType . ' ' . $ramForm; + if ($ramClockSpeed) $row['ramtype'] .= ', ' . $ramClockSpeed; + elseif ($ramSpeed) $row['ramtype'] .= ', ' . $ramSpeed; + $ramForm = false; + $ramType = false; + $ramClockSpeed = false; + } + continue; + } + if ($section === 'System Information' || $section === 'Base Board Information') { + if (empty($row['pcmodel']) && preg_match('/^\s*Product Name: +(\S.+?) *$/i', $line, $out)) { + $row['pcmodel'] = $out[1]; + } + if (empty($row['manufacturer']) && preg_match('/^\s*Manufacturer: +(\S.+?) *$/i', $line, $out)) { + $row['manufacturer'] = $out[1]; + } + } + else if ($section === 'Physical Memory Array') { + if (!$ramOk && preg_match('/Use: System Memory/i', $line)) { + $ramOk = true; + } + if ($ramOk && preg_match('/^\s*Number Of Devices: +(\S.+?) *$/i', $line, $out)) { + $row['ramslotcount'] = $out[1]; + } + if ($ramOk && preg_match('/^\s*Maximum Capacity: +(\S.+?)\s*$/i', $line, $out)) { + $row['maxram'] = preg_replace('/([MGT])B/', '$1iB', $out[1]); + } + } + else if ($section === 'Memory Device') { + if (preg_match('/^\s*Size:\s*(.*?)\s*$/i', $line, $out)) { + $row['extram'] = true; + if (preg_match('/(\d+)\s*(\w)i?B/i', $out[1], $out)) { + $out[2] = strtoupper($out[2]); + if ($out[2] === 'K' || ($out[2] === 'M' && $out[1] < 500)) { + $ramForm = $ramType = $ramSpeed = $ramClockSpeed = false; + continue; + } + if ($out[2] === 'M' && $out[1] >= 1024) { + $out[2] = 'G'; + $out[1] = floor(($out[1] + 100) / 1024); + } + $row['ramslot'][]['size'] = $out[1] . ' ' . strtoupper($out[2]) . 'iB'; + } else if (count($row['ramslot']) < 8 && (!isset($row['ramslotcount']) || $row['ramslotcount'] <= 8)) { + $row['ramslot'][]['size'] = '_____'; + } + } + if (preg_match('/^\s*Form Factor:\s*(.*?)\s*$/i', $line, $out) && $out[1] !== 'Unknown') { + $ramForm = $out[1]; + } + if (preg_match('/^\s*Type:\s*(.*?)\s*$/i', $line, $out) && $out[1] !== 'Unknown') { + $ramType = $out[1]; + } + if (preg_match('/^\s*Speed:\s*(\d.*?)\s*$/i', $line, $out)) { + $ramSpeed = $out[1]; + } + if (preg_match('/^\s*Configured Clock Speed:\s*(\d.*?)\s*$/i', $line, $out)) { + $ramClockSpeed = $out[1]; + } + } + } + if (empty($row['ramslotcount'])) $row['ramslotcount'] = count($row['ramslot']); + } + private function parseHdd(&$row, $data) { $hdds = array(); diff --git a/templates/statistics/id44.html b/templates/statistics/id44.html index d9c92c47..730839b1 100644 --- a/templates/statistics/id44.html +++ b/templates/statistics/id44.html @@ -5,7 +5,7 @@
-
+
@@ -19,7 +19,7 @@ {{/rows}}
{{lang_partitionSize}}
-
+