diff options
author | Simon Rettberg | 2016-09-13 19:42:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-09-13 19:42:09 +0200 |
commit | 1ee0014fcf0ec56af6af5937258d065ba3ee1cc9 (patch) | |
tree | 5d88384df0b3a425943f2db14370484274ee1092 /modules-available/locations | |
parent | [statistics/locations] Fix query for getting machines for a location (diff) | |
download | slx-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')
-rw-r--r-- | modules-available/locations/lang/de/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/locations/lang/en/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/locations/page.inc.php | 17 | ||||
-rw-r--r-- | modules-available/locations/style.css | 3 | ||||
-rw-r--r-- | modules-available/locations/templates/locations.html | 15 |
5 files changed, 30 insertions, 7 deletions
diff --git a/modules-available/locations/lang/de/template-tags.json b/modules-available/locations/lang/de/template-tags.json index 95a27300..29a19b85 100644 --- a/modules-available/locations/lang/de/template-tags.json +++ b/modules-available/locations/lang/de/template-tags.json @@ -18,6 +18,7 @@ "lang_locationSettings": "Raum\/Ort bearbeiten", "lang_locationsMainHeading": "Verwaltung von R\u00e4umen\/Orten", "lang_machineCount": "Rechner", + "lang_machineLoad": "Besetzt", "lang_matchingMachines": "Enthaltene Rechner", "lang_name": "Name", "lang_noParent": "Kein \u00fcbergeordneter Ort", diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json index 39436e44..6094ebce 100644 --- a/modules-available/locations/lang/en/template-tags.json +++ b/modules-available/locations/lang/en/template-tags.json @@ -18,6 +18,7 @@ "lang_locationSettings": "Edit this room or location", "lang_locationsMainHeading": "Manage rooms and locations", "lang_machineCount": "Clients", + "lang_machineLoad": "In use", "lang_matchingMachines": "Matching clients", "lang_name": "Name", "lang_noParent": "No parent", 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; diff --git a/modules-available/locations/style.css b/modules-available/locations/style.css new file mode 100644 index 00000000..86f9dfca --- /dev/null +++ b/modules-available/locations/style.css @@ -0,0 +1,3 @@ +table.locations tbody td:nth-of-type(even) { + background-color: rgba(0, 0, 0, 0.025); +}
\ No newline at end of file diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index 99fb59fd..9dcc6db1 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -3,12 +3,15 @@ <a href="?do=Locations&action=showsubnets">{{lang_thisListBySubnet}}</a> </div> <h1>{{lang_locationsMainHeading}}</h1> - <table class="table table-condensed" style="margin-bottom:0px"> + <table class="table table-condensed locations" style="margin-bottom:0px"> <tr> <th width="100%">{{lang_locationName}}</th> <th> {{#havestatistics}}{{lang_machineCount}}{{/havestatistics}} </th> + <th> + {{#havestatistics}}{{lang_machineLoad}}{{/havestatistics}} + </th> <th class="text-nowrap"> {{#havebaseconfig}}{{lang_editConfigVariables}}{{/havebaseconfig}} </th> @@ -32,6 +35,11 @@ <a class="btn btn-default btn-xs" href="?do=Statistics&show=list&filters=location={{locationid}}"><span class="glyphicon glyphicon-eye-open"></span></a> {{/havestatistics}} </td> + <td class="text-nowrap" align="right"> + {{#havestatistics}} + {{clientLoad}} + {{/havestatistics}} + </td> <td class="text-nowrap"> {{#havebaseconfig}} <div class="pull-right" style="z-index:-1"> @@ -63,6 +71,9 @@ <span class="glyphicon glyphicon-eye-open"></span> </a> </td> + <td class="text-nowrap" align="right"> + {{clientLoad}} + </td> <td></td> <td>{{defaultConfig}}</td> </tr> @@ -129,7 +140,7 @@ function slxOpenLocation(e, lid) { } return; } - var td = $('<td>').attr('colspan', '4').css('padding', '0px 0px 12px'); + var td = $('<td>').attr('colspan', '5').css('padding', '0px 0px 12px'); var tr = $('<tr>').attr('id', 'location-details-' + lid); tr.append(td); $(e).closest('tr').addClass('active slx-bold').after(tr); |