From 0914ae089ccaaa1a44d6d6fab4e6966dd06b813c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 30 Nov 2017 14:16:35 +0100 Subject: [statistics] Handle runmode and its isclient flag --- modules-available/statistics/page.inc.php | 60 +++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'modules-available/statistics/page.inc.php') diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 4919a65f..4227f3e8 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -203,7 +203,12 @@ class Page_Statistics extends Page $uuid = Request::get('uuid', false, 'string'); if ($uuid !== false) { $this->showMachine($uuid); + return; + } + $show = Request::get('show', 'stat', 'string'); + if ($show === 'projectors') { + $this->showProjectors(); return; } @@ -214,22 +219,19 @@ class Page_Statistics extends Page } $sortColumn = Request::any('sortColumn'); $sortDirection = Request::any('sortDirection'); + $filters = Filter::parseQuery($this->query); $filterSet = new FilterSet($filters); $filterSet->setSort($sortColumn, $sortDirection); - - $show = Request::get('show', 'stat', 'string'); if ($show == 'list') { Render::openTag('div', array('class' => 'row')); $this->showFilter('list', $filterSet); Render::closeTag('div'); $this->showMachineList($filterSet); return; - } elseif ($show === 'projectors') { - $this->showProjectors(); - return; } + $filterSet->filterNonClients(); Render::openTag('div', array('class' => 'row')); $this->showFilter('stat', $filterSet); $this->showSummary($filterSet); @@ -370,6 +372,10 @@ class Page_Statistics extends Page } $data['json'] = json_encode(array('labels' => $labels, 'datasets' => array($points1, $points2))); $data['query'] = $this->query; + if (Module::get('runmode') !== false) { + $res = Database::queryFirst('SELECT Count(*) AS cnt FROM runmode'); + $data['runmode'] = $res['cnt']; + } // Draw Render::addTemplate('summary', $data); } @@ -572,7 +578,13 @@ class Page_Statistics extends Page $xtra = ''; if ($filterSet->isNoId44Filter()) { - $xtra = ', data'; + $xtra .= ', data'; + } + if (Module::isAvailable('runmode')) { + $xtra .= ', runmode.module AS rmmodule'; + if (strpos($join, 'runmode') === false) { + $join .= ' LEFT JOIN runmode USING (machineuuid) '; + } } $res = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, lastseen,' . ' logintime, state, realcores, mbram, kvmstate, cpumodel, id44mb, hostname, notes IS NOT NULL AS hasnotes,' @@ -723,17 +735,37 @@ class Page_Statistics extends Page $client = Database::queryFirst('SELECT machineuuid, locationid, macaddr, clientip, firstseen, lastseen, logintime, lastboot, state,' . ' mbram, kvmstate, cpumodel, id44mb, data, hostname, currentuser, currentsession, notes FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid)); + if ($client === false) { + Message::addError('unknown-machine', $uuid); + return; + } // Hack: Get raw collected data if (Request::get('raw', false)) { Header('Content-Type: text/plain; charset=utf-8'); die($client['data']); } + // Runmode + if (Module::isAvailable('runmode')) { + $data = RunMode::getRunMode($uuid, RunMode::DATA_STRINGS); + if ($data !== false) { + $client += $data; + } + } + if (!isset($client['isclient'])) { + $client['isclient'] = true; + } // Mangle fields $NOW = time(); - $client['state_' . $client['state']] = true; - if ($client['state'] === 'OCCUPIED') { - $this->fillSessionInfo($client); + if (!$client['isclient']) { + if ($client['state'] === 'IDLE') { + $client['state'] = 'OCCUPIED'; + } + } else { + if ($client['state'] === 'OCCUPIED') { + $this->fillSessionInfo($client); + } } + $client['state_' . $client['state']] = true; $client['firstseen_s'] = date('d.m.Y H:i', $client['firstseen']); $client['lastseen_s'] = date('d.m.Y H:i', $client['lastseen']); if ($client['lastboot'] == 0) { @@ -824,6 +856,8 @@ class Page_Statistics extends Page $last = false; $first = true; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if (!$client['isclient'] && $row['typeid'] === '~session-length') + continue; // Don't differentiate between session and idle for non-clients if ($first && $row['dateline'] > $cutoff && $client['lastboot'] > $cutoff) { // Special case: offline before $spans['graph'] .= '
 
'; @@ -856,12 +890,17 @@ class Page_Statistics extends Page $color = '#e77'; } $spans['graph'] .= '
 
'; - $spans['rows'][] = $row; + if ($client['isclient']) { + $spans['rows'][] = $row; + } $last = $row; } if ($first && $client['lastboot'] > $cutoff) { // Special case: offline before $spans['graph'] .= '
 
'; + } elseif ($first) { + // Not seen in last two weeks + $spans['graph'] .= '
 
'; } if (isset($client['state_occupied'])) { $spans['graph'] .= '
 
'; @@ -882,6 +921,7 @@ class Page_Statistics extends Page $spans['rows2'] = array_slice($spans['rows'], ceil(count($spans['rows']) / 2)); $spans['rows'] = array_slice($spans['rows'], 0, ceil(count($spans['rows']) / 2)); } + $spans['isclient'] = $client['isclient']; Render::addTemplate('machine-usage', $spans); // Any hdds? if (!empty($hdds['hdds'])) { -- cgit v1.2.3-55-g7522