summaryrefslogtreecommitdiffstats
path: root/modules/statistics.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-11 18:03:19 +0100
committerSimon Rettberg2015-12-11 18:03:19 +0100
commit85e8125a235924b66c5c567f4cbe1086c6eb7575 (patch)
tree526a3cbbb58f0e82f20e3aec42e73720f9ae185f /modules/statistics.inc.php
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
Diffstat (limited to 'modules/statistics.inc.php')
-rw-r--r--modules/statistics.inc.php53
1 files changed, 49 insertions, 4 deletions
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;