summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-13 19:42:09 +0200
committerSimon Rettberg2016-09-13 19:42:09 +0200
commit1ee0014fcf0ec56af6af5937258d065ba3ee1cc9 (patch)
tree5d88384df0b3a425943f2db14370484274ee1092 /modules-available/locations/page.inc.php
parent[statistics/locations] Fix query for getting machines for a location (diff)
downloadslx-admin-1ee0014fcf0ec56af6af5937258d065ba3ee1cc9.tar.gz
slx-admin-1ee0014fcf0ec56af6af5937258d065ba3ee1cc9.tar.xz
slx-admin-1ee0014fcf0ec56af6af5937258d065ba3ee1cc9.zip
[locations] Show percent of occupied machines per location
Diffstat (limited to 'modules-available/locations/page.inc.php')
-rw-r--r--modules-available/locations/page.inc.php17
1 files changed, 12 insertions, 5 deletions
diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php
index 1bf33dda..e002ae4c 100644
--- a/modules-available/locations/page.inc.php
+++ b/modules-available/locations/page.inc.php
@@ -290,19 +290,22 @@ class Page_Locations extends Page
}
}
- private function queryMachineCount($lid, $subnets)
+ private function queryMachineCount($lid, $subnets, $xtra = '')
{
if (!isset($subnets[$lid]))
return 0;
$loc =& $subnets[$lid];
if (empty($loc['subnets'])) {
- $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid";
+ $query = "SELECT Count(*) AS cnt FROM machine WHERE (locationid = :locationid)";
} else {
- $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid OR (locationid IS NULL AND (0";
+ $query = "SELECT Count(*) AS cnt FROM machine WHERE (locationid = :locationid OR (locationid IS NULL AND (0";
foreach ($loc['subnets'] as $sub) {
$query .= ' OR INET_ATON(clientip) BETWEEN ' . $sub['startaddr'] . ' AND ' . $sub['endaddr'];
}
- $query .= '))';
+ $query .= ')))';
+ }
+ if (!empty($xtra)) {
+ $query .= ' ' . $xtra;
}
$ret = Database::queryFirst($query, array('locationid' => $lid));
return $ret['cnt'];
@@ -317,10 +320,14 @@ class Page_Locations extends Page
// Statistics: Count machines for each subnet
$unassigned = false;
if (Module::get('statistics') !== false) {
+ $DL = time() - 605;
foreach ($locs as &$location) {
$lid = (int)$location['locationid'];
$location['clientCount'] = $this->queryMachineCount($lid, $subnetsFlat);
$location['clientCountSum'] = $this->queryMachineCount($lid, $subnetsRecursive);
+ if ($location['clientCountSum'] > 0) {
+ $location['clientLoad'] = round(($this->queryMachineCount($lid, $subnetsRecursive, "AND logintime <> 0 AND lastseen > $DL") / $location['clientCountSum']) * 100) . '%';
+ }
}
$res = Database::queryFirst("SELECT Count(*) AS cnt FROM machine m"
. " LEFT JOIN subnet s ON (INET_ATON(m.clientip) BETWEEN s.startaddr AND s.endaddr)"
@@ -455,7 +462,7 @@ class Page_Locations extends Page
$data['machines'] = $count;
$data['machines_online'] = $online;
$data['machines_used'] = $used;
- $data['used_percent'] = $online === 0 ? 0 : round(100 * $used / $online);
+ $data['used_percent'] = $count === 0 ? 0 : round(($used / $count) * 100);
$data['havebaseconfig'] = Module::get('baseconfig') !== false;