diff options
author | Simon Rettberg | 2017-11-30 14:16:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-30 14:16:35 +0100 |
commit | 0914ae089ccaaa1a44d6d6fab4e6966dd06b813c (patch) | |
tree | 07630f1d02cf9f8b802c0e558748b6e40622e85c /modules-available/statistics | |
parent | [locationinfo] Added standby to the summary panel (diff) | |
download | slx-admin-0914ae089ccaaa1a44d6d6fab4e6966dd06b813c.tar.gz slx-admin-0914ae089ccaaa1a44d6d6fab4e6966dd06b813c.tar.xz slx-admin-0914ae089ccaaa1a44d6d6fab4e6966dd06b813c.zip |
[statistics] Handle runmode and its isclient flag
Diffstat (limited to 'modules-available/statistics')
7 files changed, 140 insertions, 53 deletions
diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php index b16bd9fb..6e437a71 100644 --- a/modules-available/statistics/inc/filter.inc.php +++ b/modules-available/statistics/inc/filter.inc.php @@ -29,7 +29,7 @@ class Filter $addendum = ''; /* check if we have to do some parsing*/ - if (Page_Statistics::$columns[$this->column]['type'] == 'date') { + if (Page_Statistics::$columns[$this->column]['type'] === 'date') { $args[$key] = strtotime($this->argument); } else { $args[$key] = $this->argument; @@ -180,8 +180,7 @@ class StateFilter extends Filter { public function __construct($operator, $argument) { - $this->operator = $operator; - $this->argument = $argument; + parent::__construct(null, $operator, $argument); } public function whereClause(&$args, &$joins) @@ -236,3 +235,20 @@ class SubnetFilter extends Filter } } +class IsClientFilter extends Filter +{ + public function __construct($argument) + { + parent::__construct(null, null, $argument); + } + + public function whereClause(&$args, &$joins) + { + if ($this->argument) { + $joins[] = ' LEFT JOIN runmode USING (machineuuid)'; + return "(runmode.isclient <> 0 OR runmode.isclient IS NULL)"; + } + $joins[] = ' INNER JOIN runmode USING (machineuuid)'; + return "runmode.isclient = 0"; + } +} diff --git a/modules-available/statistics/inc/filterset.inc.php b/modules-available/statistics/inc/filterset.inc.php index c73feeef..25c5c8fa 100644 --- a/modules-available/statistics/inc/filterset.inc.php +++ b/modules-available/statistics/inc/filterset.inc.php @@ -2,6 +2,9 @@ class FilterSet { + /** + * @var \Filter[] + */ private $filters; private $sortDirection; private $sortColumn; @@ -39,7 +42,7 @@ class FilterSet $where .= $sep . $filter->whereClause($args, $joins); } } - $join = implode('', array_unique($joins)); + $join = implode(' ', array_unique($joins)); $col = $this->sortColumn; $isMapped = array_key_exists('map_sort', Page_Statistics::$columns[$col]); @@ -72,4 +75,13 @@ class FilterSet { return $this->sortColumn; } + + public function filterNonClients() + { + if (Module::get('runmode') === false) + return; + // Runmode module exists, add filter + $this->filters[] = new IsClientFilter(true); + } + } 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'] .= '<div style="background:#444;left:0%;width:' . round((min($row['dateline'], $client['lastboot']) - $cutoff) * $scale, 2) . '%"> </div>'; @@ -856,12 +890,17 @@ class Page_Statistics extends Page $color = '#e77'; } $spans['graph'] .= '<div style="background:' . $color . ';left:' . round(($row['dateline'] - $cutoff) * $scale, 2) . '%;width:' . round(($row['data']) * $scale, 2) . '%"> </div>'; - $spans['rows'][] = $row; + if ($client['isclient']) { + $spans['rows'][] = $row; + } $last = $row; } if ($first && $client['lastboot'] > $cutoff) { // Special case: offline before $spans['graph'] .= '<div style="background:#444;left:0%;width:' . round(($client['lastboot'] - $cutoff) * $scale, 2) . '%"> </div>'; + } elseif ($first) { + // Not seen in last two weeks + $spans['graph'] .= '<div style="background:#444;left:0%;width:100%"> </div>'; } if (isset($client['state_occupied'])) { $spans['graph'] .= '<div style="background:#e99;left:' . round(($client['logintime'] - $cutoff) * $scale, 2) . '%;width:' . round(($NOW - $client['logintime'] + 900) * $scale, 2) . '%"> </div>'; @@ -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'])) { diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 4755c3c1..0e88a15c 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -74,6 +74,7 @@ {{/state_STANDBY}} <a href="?do=Statistics&uuid={{machineuuid}}"><b>{{hostname}}</b></a> <div class="small">{{machineuuid}}</div> + {{#rmmodule}}<div class="small">{{lang_runMode}}: <a class="slx-bold" href="?do=runmode&module={{rmmodule}}">{{rmmodule}}</a></div>{{/rmmodule}} </td> <td><b><a href="?do=Statistics&show=list&filters=subnet={{subnet}}">{{subnet}}</a>{{lastoctet}}</b><br>{{macaddr}}</td> <td class="text-right">{{lastseen}}</td> diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html index 1854a03b..14d388d3 100644 --- a/modules-available/statistics/templates/machine-main.html +++ b/modules-available/statistics/templates/machine-main.html @@ -80,6 +80,14 @@ {{/session}} </td> </tr> + {{#modeid}} + <tr> + <td class="text-nowrap">{{lang_runMode}}</td> + <td> + <a href="?do={{modeid}}">{{moduleName}}</a> – {{modeName}} + </td> + </tr> + {{/modeid}} </table> </div> </div> diff --git a/modules-available/statistics/templates/machine-usage.html b/modules-available/statistics/templates/machine-usage.html index ef969fc6..be435ee5 100644 --- a/modules-available/statistics/templates/machine-usage.html +++ b/modules-available/statistics/templates/machine-usage.html @@ -5,46 +5,50 @@ {{lang_usageDetails}} </div> <div class="panel-body"> - <div class="row"> - <div class="col-sm-6"> - <table class="table table-condensed"> - <tr> - <th>{{lang_eventType}}</th> - <th>{{lang_when}}</th> - <th>{{lang_duration}}</th> - </tr> - {{#rows}} - <tr> - <td><span class="glyphicon glyphicon-{{glyph}}"></span></td> - <td>{{from}}</td> - <td>{{duration}}</td> - </tr> - {{/rows}} - </table> + {{#isclient}} + <div class="row"> + <div class="col-sm-6"> + <table class="table table-condensed"> + <tr> + <th>{{lang_eventType}}</th> + <th>{{lang_when}}</th> + <th>{{lang_duration}}</th> + </tr> + {{#rows}} + <tr> + <td><span class="glyphicon glyphicon-{{glyph}}"></span></td> + <td>{{from}}</td> + <td>{{duration}}</td> + </tr> + {{/rows}} + </table> + </div> + <div class="col-sm-6"> + <table class="table table-condensed"> + {{#hasrows2}} + <tr> + <th>{{lang_eventType}}</th> + <th>{{lang_when}}</th> + <th>{{lang_duration}}</th> + </tr> + {{/hasrows2}} + {{#rows2}} + <tr> + <td><span class="glyphicon glyphicon-{{glyph}}"></span></td> + <td>{{from}}</td> + <td>{{duration}}</td> + </tr> + {{/rows2}} + </table> + </div> </div> - <div class="col-sm-6"> - <table class="table table-condensed"> - {{#hasrows2}} - <tr> - <th>{{lang_eventType}}</th> - <th>{{lang_when}}</th> - <th>{{lang_duration}}</th> - </tr> - {{/hasrows2}} - {{#rows2}} - <tr> - <td><span class="glyphicon glyphicon-{{glyph}}"></span></td> - <td>{{from}}</td> - <td>{{duration}}</td> - </tr> - {{/rows2}} - </table> - </div> - </div> + {{/isclient}} <div class="timebar"> {{{graph}}}</div> - <div> - {{lang_timebarDesc}} - </div> + {{#isclient}} + <div> + {{lang_timebarDesc}} + </div> + {{/isclient}} </div> </div> </div> diff --git a/modules-available/statistics/templates/summary.html b/modules-available/statistics/templates/summary.html index 642c48fc..fe9559ed 100644 --- a/modules-available/statistics/templates/summary.html +++ b/modules-available/statistics/templates/summary.html @@ -1,6 +1,11 @@ <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-body"> + {{#runmode}} + <div class="pull-right"> + <a href="?do=runmode">{{lang_runmodeMachines}}</a>: <b>{{runmode}}</b> + </div> + {{/runmode}} <div> {{lang_knownMachines}}: <b>{{known}}</b>  <a href="?do=Statistics&show=stat&filters={{query}}~,~state=on">{{lang_onlineMachines}}</a>: <b>{{online}}</b>  @@ -10,8 +15,9 @@ <div> <span class="glyphicon glyphicon-exclamation-sign red"></span> <a href="?do=Statistics&show=list&filters={{query}}~,~badsectors>=10"> - {{lang_withBadSectors}}: <b>{{badhdd}}</b> + {{lang_withBadSectors}}: </a> + <b>{{badhdd}}</b> </div> {{/badhdd}} </div> |