diff options
author | Christian Hofmaier | 2017-04-12 14:30:18 +0200 |
---|---|---|
committer | Christian Hofmaier | 2017-04-12 14:30:18 +0200 |
commit | 9f27c7cdeb1df2f9c42373f419c6621d4faa71ca (patch) | |
tree | e55c6e1d95685df2117401e97f946b962f4e0f47 /modules-available/statistics_reporting | |
parent | [permissionmanager] changed description to tooltips (diff) | |
parent | [rebootcontrol] New module for shutting down and rebooting clients (diff) | |
download | slx-admin-9f27c7cdeb1df2f9c42373f419c6621d4faa71ca.tar.gz slx-admin-9f27c7cdeb1df2f9c42373f419c6621d4faa71ca.tar.xz slx-admin-9f27c7cdeb1df2f9c42373f419c6621d4faa71ca.zip |
Merge branches 'master' and 'permission-manager' of git.openslx.org:openslx-ng/slx-admin into permission-manager
Diffstat (limited to 'modules-available/statistics_reporting')
5 files changed, 28 insertions, 15 deletions
diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index a48f74c2..afb18a23 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -4,7 +4,7 @@ if (RemoteReport::isReportingEnabled()) { $nextReporting = RemoteReport::getReportingTimestamp(); // It's time to generate a new report - if ($nextReporting <= time()) { + while ($nextReporting <= time()) { RemoteReport::writeNextReportingTimestamp(); $from = strtotime("-7 days", $nextReporting); @@ -18,6 +18,9 @@ if (RemoteReport::isReportingEnabled()) { if ($code != 200) { EventLog::warning("Statistics Reporting failed: " . $code, $result); + } else { + EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL); } + $nextReporting = strtotime("+7 days", $nextReporting); } }
\ No newline at end of file diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php index f65ee868..da3a9a26 100644 --- a/modules-available/statistics_reporting/inc/getdata.inc.php +++ b/modules-available/statistics_reporting/inc/getdata.inc.php @@ -40,6 +40,7 @@ class GetData $res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $median = self::calcMedian(self::calcMedian($row['medianSessionLength'])); $entry = array( 'location' => ($anonymize ? $row['locHash'] : $row['locName']), @@ -69,6 +70,7 @@ class GetData $res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $median = self::calcMedian(self::calcMedian($row['medianSessionLength'])); $entry = array( 'hostname' => ($anonymize ? $row['clientHash'] : $row['clientName']), @@ -116,12 +118,20 @@ class GetData $data = array(); $vm = $anonymize ? 'vmHash' : 'name'; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $data[] = array('vm' => $row[$vm], 'sessions' => $row['count']); } return $data; } - + private static function nullToZero(&$row) + { + foreach ($row as &$field) { + if (is_null($field)) { + $field = 0; + } + } + } // Format $seconds into ".d .h .m .s" format (day, hour, minute, second) private static function formatSeconds($seconds) diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index 3e944c92..2269e764 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -8,16 +8,16 @@ class Queries public static function getClientStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) { $notassigned = Dictionary::translate('notAssigned', true); Database::exec("SET SESSION group_concat_max_len = 1000000000"); - $res = Database::simpleQuery("SELECT name AS clientName, timeSum, medianSessionLength, offlineSum, IFNULL(lastStart, 0) as lastStart, IFNULL(lastLogout, 0) as lastLogout, longSessions, shortSessions, locId, locName, MD5(CONCAT(locId, :salt)) AS locHash, MD5(CONCAT(t1.uuid, :salt)) AS clientHash FROM ( + $res = Database::simpleQuery("SELECT t2.name AS clientName, timeSum, medianSessionLength, offlineSum, IFNULL(lastStart, 0) as lastStart, IFNULL(lastLogout, 0) as lastLogout, longSessions, shortSessions, t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, MD5(CONCAT(t2.uuid, :salt)) AS clientHash FROM ( SELECT machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions', MAX(sessionTable.endInBound) AS 'lastLogout' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable - INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON sessionTable.machineuuid = machine.machineuuid GROUP BY machine.machineuuid ) t1 RIGHT JOIN ( - SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.endInBound) AS 'lastStart', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId' + SELECT IF(machine.hostname = '', machine.clientip, machine.hostname) AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.endInBound) AS 'lastStart', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId' FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable - INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON offlineTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.machineuuid ) t2 @@ -30,17 +30,17 @@ class Queries public static function getLocationStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) { $notassigned = Dictionary::translate('notAssigned', true); Database::exec("SET SESSION group_concat_max_len = 1000000000"); - $res = Database::simpleQuery("SELECT t1.locId, locName AS locName, MD5(CONCAT(t1.locId, :salt)) AS locHash, timeSum, medianSessionLength, offlineSum, longSessions, shortSessions FROM ( + $res = Database::simpleQuery("SELECT t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, timeSum, medianSessionLength, offlineSum, longSessions, shortSessions FROM ( SELECT location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable - INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON sessionTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.locationid ) t1 RIGHT JOIN ( SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum' FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable - INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON offlineTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.locationid ) t2 diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 7aad8b3a..4c5f604b 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -40,7 +40,7 @@ class RemoteReport if ($ts === 0) { // No timestamp stored yet - might be a fresh install // schedule for next time - self::updateNextReportingTimestamp(); + self::writeNextReportingTimestamp(); $ts = Property::get(self::NEXT_SUBMIT_ID, 0); } elseif ($ts < strtotime('last monday')) { // Too long ago, move forward to last monday @@ -63,18 +63,16 @@ class RemoteReport * Generate the multi-dimensional array containing the anonymized * (weekly) statistics to report. * - * @param $from start timestamp - * @param $to end timestamp + * @param int $from start timestamp + * @param int $to end timestamp * @return array wrapped up statistics, ready for reporting */ public static function generateReport($from, $to) { GetData::$from = $from; GetData::$to = $to; - GetData::$salt = bin2hex(Util::randomBytes(20)); + GetData::$salt = bin2hex(Util::randomBytes(20, false)); $data = GetData::total(GETDATA_ANONYMOUS); $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); - $data['perClient'] = GetData::perClient(GETDATA_ANONYMOUS); - $data['perUser'] = GetData::perUser(GETDATA_ANONYMOUS); $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); $data['tsFrom'] = $from; $data['tsTo'] = $to; diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index f08daf1c..a5ac828b 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -150,6 +150,8 @@ updateColumn(box); } }); + + $('th[data-sort]').first().click(); }); function updateColumn(checkbox) { |