summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-11 18:03:19 +0100
committerSimon Rettberg2015-12-11 18:03:19 +0100
commit85e8125a235924b66c5c567f4cbe1086c6eb7575 (patch)
tree526a3cbbb58f0e82f20e3aec42e73720f9ae185f
parent[statistics] Show PC status (on/off/inuse) (diff)
downloadslx-admin-85e8125a235924b66c5c567f4cbe1086c6eb7575.tar.gz
slx-admin-85e8125a235924b66c5c567f4cbe1086c6eb7575.tar.xz
slx-admin-85e8125a235924b66c5c567f4cbe1086c6eb7575.zip
[statistics] Show summary at top, show session details for occupied clients
-rw-r--r--lang/de/templates/statistics/machine-main.json1
-rw-r--r--lang/de/templates/statistics/summary.json6
-rw-r--r--lang/en/templates/statistics/machine-main.json1
-rw-r--r--lang/en/templates/statistics/summary.json6
-rw-r--r--lang/pt/templates/statistics/summary.json3
-rw-r--r--modules/statistics.inc.php53
-rw-r--r--templates/statistics/clientlist.html10
-rw-r--r--templates/statistics/machine-main.html9
-rw-r--r--templates/statistics/summary.html20
9 files changed, 103 insertions, 6 deletions
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 @@
<td class="text-right">{{lastseen}}</td>
<td class="{{kvmclass}}">{{kvmstate}}</td>
<td class="text-right {{ramclass}}">{{gbram}}&thinsp;GiB</td>
- <td class="text-right {{hddclass}}">{{gbtmp}}&thinsp;GiB</td>
+ <td class="text-right {{hddclass}}">
+ {{gbtmp}}&thinsp;GiB
+ {{#badsectors}}<div>
+ <span class="glyphicon glyphicon-exclamation-sign"></span>
+ {{badsectors}}
+ </div>{{/badsectors}}
+ </td>
<td>{{lang_realCores}}: {{realcores}}<div class="small">{{cpumodel}}</div></td>
</tr>
{{/rows}}
-</table> \ No newline at end of file
+</table>
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 @@
<span class="glyphicon glyphicon-ok green"></span> {{lang_machineIdle}}
{{/state_idle}}
{{#state_occupied}}
+ {{#username}}
+ <span class="glyphicon glyphicon-user red"></span> {{lang_machineOccupiedBy}} <b>{{username}}</b>
+ {{/username}}
+ {{^username}}
<span class="glyphicon glyphicon-user red"></span> {{lang_machineOccupied}}
+ {{/username}}
+ <div>{{logintime}}</div>
{{/state_occupied}}
+ {{#session}}
+ <div>{{session}}</div>
+ {{/session}}
</td>
</tr>
</table>
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 @@
+<div class="col-md-12">
+ <div class="panel panel-default">
+ <div class="panel-body">
+ <div>
+ {{lang_knownMachines}}: <b>{{known}}</b>&emsp;
+ {{lang_onlineMachines}}: <b>{{online}}</b>&emsp;
+ {{lang_inUseMachines}}: <b>{{used}}</b> (<b>{{usedpercent}}%</b>)
+ </div>
+ {{#badhdd}}
+ <div>
+ <span class="glyphicon glyphicon-exclamation-sign red"></span>
+ <a href="?do=Statistics&amp;filter=badsectors&amp;argument=10">
+ {{lang_withBadSectors}}: <b>{{badhdd}}</b>
+ </a>
+ </div>
+ {{/badhdd}}
+ </div>
+ </div>
+</div>
+