From 1ee0014fcf0ec56af6af5937258d065ba3ee1cc9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 13 Sep 2016 19:42:09 +0200 Subject: [locations] Show percent of occupied machines per location --- modules-available/locations/lang/de/template-tags.json | 1 + modules-available/locations/lang/en/template-tags.json | 1 + modules-available/locations/page.inc.php | 17 ++++++++++++----- modules-available/locations/style.css | 3 +++ modules-available/locations/templates/locations.html | 15 +++++++++++++-- 5 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 modules-available/locations/style.css 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 @@ {{lang_thisListBySubnet}}

{{lang_locationsMainHeading}}

- +
+ @@ -32,6 +35,11 @@ {{/havestatistics}} + + @@ -129,7 +140,7 @@ function slxOpenLocation(e, lid) { } return; } - var td = $('').attr('id', 'location-details-' + lid); tr.append(td); $(e).closest('tr').addClass('active slx-bold').after(tr); -- cgit v1.2.3-55-g7522
{{lang_locationName}} {{#havestatistics}}{{lang_machineCount}}{{/havestatistics}} + {{#havestatistics}}{{lang_machineLoad}}{{/havestatistics}} + {{#havebaseconfig}}{{lang_editConfigVariables}}{{/havebaseconfig}} + {{#havestatistics}} + {{clientLoad}} + {{/havestatistics}} + {{#havebaseconfig}}
@@ -63,6 +71,9 @@
+ {{clientLoad}} + {{defaultConfig}}
').attr('colspan', '4').css('padding', '0px 0px 12px'); + var td = $('').attr('colspan', '5').css('padding', '0px 0px 12px'); var tr = $('