From 85e8125a235924b66c5c567f4cbe1086c6eb7575 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 11 Dec 2015 18:03:19 +0100 Subject: [statistics] Show summary at top, show session details for occupied clients --- lang/de/templates/statistics/machine-main.json | 1 + lang/de/templates/statistics/summary.json | 6 +++ lang/en/templates/statistics/machine-main.json | 1 + lang/en/templates/statistics/summary.json | 6 +++ lang/pt/templates/statistics/summary.json | 3 ++ modules/statistics.inc.php | 53 ++++++++++++++++++++++++-- templates/statistics/clientlist.html | 10 ++++- templates/statistics/machine-main.html | 9 +++++ templates/statistics/summary.html | 20 ++++++++++ 9 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 lang/de/templates/statistics/summary.json create mode 100644 lang/en/templates/statistics/summary.json create mode 100644 lang/pt/templates/statistics/summary.json create mode 100644 templates/statistics/summary.html diff --git a/lang/de/templates/statistics/machine-main.json b/lang/de/templates/statistics/machine-main.json index acf9c323..47c3e266 100644 --- a/lang/de/templates/statistics/machine-main.json +++ b/lang/de/templates/statistics/machine-main.json @@ -11,6 +11,7 @@ "lang_macAddr": "MAC-Adresse", "lang_machineIdle": "Eingeschaltet, ungenutzt", "lang_machineOccupied": "Eingeschaltet, in Verwendung", + "lang_machineOccupiedBy": "In Verwendung durch", "lang_machineOff": "Kein bwLehrpool gestartet", "lang_machineSummary": "Zusammenfassung", "lang_maximumAbbrev": "Max.", diff --git a/lang/de/templates/statistics/summary.json b/lang/de/templates/statistics/summary.json new file mode 100644 index 00000000..30189871 --- /dev/null +++ b/lang/de/templates/statistics/summary.json @@ -0,0 +1,6 @@ +{ + "lang_inUseMachines": "In Verwendung", + "lang_knownMachines": "Bekannte Clients", + "lang_onlineMachines": "Gestartete Clients", + "lang_withBadSectors": "Clients mit potentiell defekten Festplatten (mehr als 10 defekte Sektoren)" +} \ No newline at end of file diff --git a/lang/en/templates/statistics/machine-main.json b/lang/en/templates/statistics/machine-main.json index ff1e481f..1addd437 100644 --- a/lang/en/templates/statistics/machine-main.json +++ b/lang/en/templates/statistics/machine-main.json @@ -11,6 +11,7 @@ "lang_macAddr": "MAC address", "lang_machineIdle": "Powered on, unused", "lang_machineOccupied": "Powered on, in use", + "lang_machineOccupiedBy": "In use by", "lang_machineOff": "bwLehrpool not running", "lang_machineSummary": "Summary", "lang_maximumAbbrev": "max.", diff --git a/lang/en/templates/statistics/summary.json b/lang/en/templates/statistics/summary.json new file mode 100644 index 00000000..b57c290f --- /dev/null +++ b/lang/en/templates/statistics/summary.json @@ -0,0 +1,6 @@ +{ + "lang_inUseMachines": "In use", + "lang_knownMachines": "Known clients", + "lang_onlineMachines": "Online clients", + "lang_withBadSectors": "Clients with potentially bad HDDs (more than 10 reallocated sectors)" +} \ No newline at end of file diff --git a/lang/pt/templates/statistics/summary.json b/lang/pt/templates/statistics/summary.json new file mode 100644 index 00000000..c44dc44f --- /dev/null +++ b/lang/pt/templates/statistics/summary.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/modules/statistics.inc.php b/modules/statistics.inc.php index 16161d9f..dd04771f 100644 --- a/modules/statistics.inc.php +++ b/modules/statistics.inc.php @@ -51,6 +51,7 @@ class Page_Statistics extends Page } Render::addScriptBottom('chart.min'); Render::openTag('div', array('class' => 'row')); + $this->showSummary(); $this->showMemory(); $this->showId44(); $this->showKvmState(); @@ -84,6 +85,24 @@ class Page_Statistics extends Page } } + private function showSummary() + { + $cutoff = time() - 86400 * 30; + $online = time() - 610; + $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff"); + $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online"); + $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online AND logintime <> 0"); + $hdd = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE badsectors > 10 AND lastseen > $cutoff"); + $data = array( + 'known' => $known['val'], + 'online' => $on['val'], + 'used' => $used['val'], + 'usedpercent' => round($used['val'] / $on['val'] * 100), + 'badhdd' => $hdd['val'] + ); + Render::addTemplate('statistics/summary', $data); + } + private function showCpuModels() { global $STATS_COLORS; @@ -265,19 +284,22 @@ class Page_Statistics extends Page $argument = preg_replace('/[^0-9\.:]/', '', $argument); $where = " clientip LIKE '$argument%'"; $args = array(); + } elseif ($filter === 'badsectors') { + $where = " badsectors >= :argument "; + $args = array('argument' => $argument); } else { Message::addError('invalid-filter'); return; } $res = Database::simpleQuery("SELECT machineuuid, macaddr, clientip, firstseen, lastseen," - . " logintime, lastboot, realcores, mbram, kvmstate, cpumodel, id44mb, hostname, notes IS NOT NULL AS hasnotes FROM machine" + . " logintime, lastboot, realcores, mbram, kvmstate, cpumodel, id44mb, hostname, notes IS NOT NULL AS hasnotes, badsectors FROM machine" . " WHERE $where ORDER BY lastseen DESC, clientip ASC", $args); $rows = array(); $NOW = time(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($NOW - $row['lastseen'] > 610) { $row['state_off'] = true; - } elseif ($NOW - $row['logintime'] > 610) { + } elseif ($row['logintime'] == 0) { $row['state_idle'] = true; } else { $row['state_occupied'] = true; @@ -348,6 +370,27 @@ class Page_Statistics extends Page return ($array[$best] + $array[$best - 1]) / 2; } + private function fillSessionInfo(&$row) + { + $res = Database::simpleQuery("SELECT dateline, username, data FROM statistic" + . " WHERE clientip = :ip AND typeid = '.vmchooser-session-name'" + . " AND dateline BETWEEN :start AND :end", array( + 'ip' => $row['clientip'], + 'start' => $row['logintime'] - 60, + 'end' => $row['logintime'] + 300 + )); + $session = false; + while ($r = $res->fetch(PDO::FETCH_ASSOC)) { + if ($session === false || abs($session['dateline'] - $row['logintime']) > abs($r['dateline'] - $row['logintime'])) { + $session = $r; + } + } + if ($session !== false) { + $row['session'] = $session['data']; + $row['username'] = $session['username']; + } + } + private function showMachine($uuid) { $row = Database::queryFirst("SELECT machineuuid, macaddr, clientip, firstseen, lastseen, logintime, lastboot," @@ -357,14 +400,16 @@ class Page_Statistics extends Page $NOW = time(); if ($NOW - $row['lastseen'] > 610) { $row['state_off'] = true; - } elseif ($NOW - $row['logintime'] > 610) { + } elseif ($row['logintime'] == 0) { $row['state_idle'] = true; } else { $row['state_occupied'] = true; + $this->fillSessionInfo($row); } $row['firstseen'] = date('d.m.Y H:i', $row['firstseen']); $row['lastseen'] = date('d.m.Y H:i', $row['lastseen']); $row['lastboot'] = date('d.m.Y H:i', $row['lastboot']); + $row['logintime'] = date('d.m.Y H:i', $row['logintime']); $row['gbram'] = round(round($row['mbram'] / 500) / 2, 1); $row['gbtmp'] = round($row['id44mb'] / 1024); $row['ramclass'] = $this->ramColorClass($row['mbram']); @@ -503,7 +548,7 @@ class Page_Statistics extends Page } elseif (preg_match('/^Units =.*= (\d+) bytes/i', $line, $out)) { // Unit for start and end $unit = $out[1] / (1024 * 1024); // Convert so that multiplying by unit yields MiB - } else if (isset($hdd) && $unit !== 0 && preg_match(',^/dev/(\S+)\s+.*\s(\d+)\s+(\d+)\s+\d+\s+([0-9a-f]+)\s+(.*)$,i', $line, $out)) { + } else if (isset($hdd) && $unit !== 0 && preg_match(',^/dev/(\S+)\s+.*\s(\d+)[\+\-]?\s+(\d+)[\+\-]?\s+\d+[\+\-]?\s+([0-9a-f]+)\s+(.*)$,i', $line, $out)) { // Some partition $type = strtolower($out[4]); if ($type === '5' || $type === 'f' || $type === '85') continue; diff --git a/templates/statistics/clientlist.html b/templates/statistics/clientlist.html index eb3c6bd4..8e8565fe 100644 --- a/templates/statistics/clientlist.html +++ b/templates/statistics/clientlist.html @@ -32,8 +32,14 @@ {{lastseen}} {{kvmstate}} {{gbram}} GiB - {{gbtmp}} GiB + + {{gbtmp}} GiB + {{#badsectors}}
+ + {{badsectors}} +
{{/badsectors}} + {{lang_realCores}}: {{realcores}}
{{cpumodel}}
{{/rows}} - \ No newline at end of file + diff --git a/templates/statistics/machine-main.html b/templates/statistics/machine-main.html index 03e95381..f9ca1c5d 100644 --- a/templates/statistics/machine-main.html +++ b/templates/statistics/machine-main.html @@ -51,8 +51,17 @@ {{lang_machineIdle}} {{/state_idle}} {{#state_occupied}} + {{#username}} + {{lang_machineOccupiedBy}} {{username}} + {{/username}} + {{^username}} {{lang_machineOccupied}} + {{/username}} +
{{logintime}}
{{/state_occupied}} + {{#session}} +
{{session}}
+ {{/session}} diff --git a/templates/statistics/summary.html b/templates/statistics/summary.html new file mode 100644 index 00000000..fb6466fc --- /dev/null +++ b/templates/statistics/summary.html @@ -0,0 +1,20 @@ +
+
+
+
+ {{lang_knownMachines}}: {{known}}  + {{lang_onlineMachines}}: {{online}}  + {{lang_inUseMachines}}: {{used}} ({{usedpercent}}%) +
+ {{#badhdd}} +
+ + + {{lang_withBadSectors}}: {{badhdd}} + +
+ {{/badhdd}} +
+
+
+ -- cgit v1.2.3-55-g7522