|
static | isActive () |
| Is session statistics active at all? More...
|
|
static | createRawEntry ($a_session_id, $a_session_type, $a_timestamp, $a_user_id) |
| Create raw data entry. More...
|
|
static | closeRawEntry ($a_session_id, $a_context=null, $a_expired_at=null) |
| Close raw data entry. More...
|
|
static | aggretateRaw ($a_now) |
| Aggregate raw session data (older than given time) More...
|
|
static | aggregateRawHelper ($a_begin, $a_end) |
| Aggregate statistics data for one slot. More...
|
|
static | getLastMaxedOut () |
| Get latest slot during which sessions were maxed out. More...
|
|
static | getMaxedOutDuration ($a_from, $a_to) |
| Get maxed out duration in given timeframe. More...
|
|
static | getNumberOfSessionsByType ($a_from, $a_to) |
| Get session counters by type (opened, closed) More...
|
|
static | getActiveSessions ($a_from, $a_to) |
| Get active sessions aggregated data. More...
|
|
static | getLastAggregation () |
| Get timestamp of last aggregation. More...
|
|
static | getLimitForSlot ($a_timestamp) |
| Get max session setting for given timestamp. More...
|
|
static | updateLimitLog ($a_new_value) |
| Log max session setting. More...
|
|
◆ aggregateRawHelper()
static ilSessionStatistics::aggregateRawHelper |
( |
|
$a_begin, |
|
|
|
$a_end |
|
) |
| |
|
static |
Aggregate statistics data for one slot.
- Parameters
-
timestamp | $a_begin | |
timestamp | $a_end | |
Definition at line 281 of file class.ilSessionStatistics.php.
References $action, $DIC, $events, $ilDB, $ilSetting, ilSession\SESSION_CLOSE_EXPIRE, ilSession\SESSION_CLOSE_FIRST, ilSession\SESSION_CLOSE_IDLE, ilSession\SESSION_CLOSE_LIMIT, ilSession\SESSION_CLOSE_LOGIN, and ilSession\SESSION_CLOSE_USER.
285 $ilDB = $DIC[
'ilDB'];
297 $closed_counter =
$events = array();
299 foreach (self::getRawData($a_begin, $a_end) as $item) {
308 if ($item[
"start_time"] >= $a_begin) {
310 $events[$item[
"start_time"]][] = 1;
313 if ($item[
"end_time"] && $item[
"end_time"] <= $a_end) {
314 if (in_array($item[
"end_context"], $separate_closed)) {
315 $closed_counter[$item[
"end_context"]]++;
317 $closed_counter[0]++;
319 $events[$item[
"end_time"]][] = -1;
324 $active_begin = self::getNumberOfActiveRawSessions($a_begin - 1);
325 $active_end = $active_min = $active_max = $active_avg = $active_begin;
329 $last_update_avg = $a_begin - 1;
330 $slot_seconds = self::SLOT_SIZE * 60;
335 foreach (
$events as $ts => $actions) {
337 foreach ($actions as
$action) {
349 if ($active_end > $active_max) {
350 $active_max = $active_end;
354 if ($active_end < $active_min) {
355 $active_min = $active_end;
359 $diff = $ts - $last_update_avg;
360 $active_avg += $diff / $slot_seconds * $active_end;
361 $last_update_avg = $ts;
366 if ($last_update_avg < $a_end) {
367 $diff = $a_end - $last_update_avg;
368 $active_avg += $diff / $slot_seconds * $active_end;
371 $active_avg = round($active_avg);
378 $max_sessions = self::getLimitForSlot($a_begin);
382 "active_min" => array(
"integer", $active_min),
383 "active_max" => array(
"integer", $active_max),
384 "active_avg" => array(
"integer", $active_avg),
385 "active_end" => array(
"integer", $active_end),
386 "opened" => array(
"integer", $opened_counter),
393 "closed_misc" => array(
"integer", (
int) $closed_counter[0]),
394 "max_sessions" => array(
"integer", (
int) $max_sessions)
399 array(
"slot_begin" => array(
"integer", $a_begin),
400 "slot_end" => array(
"integer", $a_end))
const SESSION_CLOSE_LOGIN
const SESSION_CLOSE_EXPIRE
const SESSION_CLOSE_LIMIT
const SESSION_CLOSE_FIRST
◆ aggretateRaw()
static ilSessionStatistics::aggretateRaw |
( |
|
$a_now | ) |
|
|
static |
Aggregate raw session data (older than given time)
- Parameters
-
Definition at line 259 of file class.ilSessionStatistics.php.
Referenced by ilSession\_writeData(), and ilSessionStatisticsGUI\adminSync().
261 if (!self::isActive()) {
265 $slot = self::createNewAggregationSlot($a_now);
266 while (is_array($slot)) {
267 self::aggregateRawHelper($slot[0], $slot[1]);
268 $slot = self::createNewAggregationSlot($a_now);
272 self::deleteAggregatedRaw($a_now);
◆ closeRawEntry()
static ilSessionStatistics::closeRawEntry |
( |
|
$a_session_id, |
|
|
|
$a_context = null , |
|
|
|
$a_expired_at = null |
|
) |
| |
|
static |
Close raw data entry.
- Parameters
-
int | array | $a_session_id | |
int | $a_context | |
int | bool | $a_expired_at | |
Definition at line 75 of file class.ilSessionStatistics.php.
References $DIC, $id, and $ilDB.
Referenced by ilSession\_destroy().
81 if (!self::isActive()) {
86 if (!is_array($a_session_id)) {
88 $end_time = $a_expired_at;
92 $sql =
"UPDATE usr_session_stats_raw" .
93 " SET end_time = " .
$ilDB->quote($end_time,
"integer");
95 $sql .=
",end_context = " .
$ilDB->quote($a_context,
"integer");
97 $sql .=
" WHERE session_id = " .
$ilDB->quote($a_session_id,
"text") .
98 " AND end_time IS NULL";
99 $ilDB->manipulate($sql);
102 elseif (!$a_expired_at) {
103 $sql =
"UPDATE usr_session_stats_raw" .
104 " SET end_time = " .
$ilDB->quote(time(),
"integer");
106 $sql .=
",end_context = " .
$ilDB->quote($a_context,
"integer");
108 $sql .=
" WHERE " .
$ilDB->in(
"session_id", $a_session_id,
false,
"text") .
109 " AND end_time IS NULL";
110 $ilDB->manipulate($sql);
114 foreach ($a_session_id as
$id => $ts) {
115 $sql =
"UPDATE usr_session_stats_raw" .
116 " SET end_time = " .
$ilDB->quote($ts,
"integer");
118 $sql .=
",end_context = " .
$ilDB->quote($a_context,
"integer");
120 $sql .=
" WHERE session_id = " .
$ilDB->quote(
$id,
"text") .
121 " AND end_time IS NULL";
122 $ilDB->manipulate($sql);
if(!array_key_exists('StateId', $_REQUEST)) $id
◆ createNewAggregationSlot()
static ilSessionStatistics::createNewAggregationSlot |
( |
|
$a_now | ) |
|
|
staticprotected |
Create new slot (using table lock)
- Parameters
-
- Returns
- array begin, end
Definition at line 223 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, and ilDBInterface\insert().
227 $ilDB = $DIC[
'ilDB'];
229 $ilAtomQuery =
$ilDB->buildAtomQuery();
230 $ilAtomQuery->addTableLock(
"usr_session_stats");
235 $slot = self::getCurrentSlot($a_now);
236 if (!is_array($slot)) {
243 "slot_begin" => array(
"integer", $slot[0]),
244 "slot_end" => array(
"integer", $slot[1]),
246 $ilDB->
insert(
"usr_session_stats", $fields);
insert($table_name, $values)
◆ createRawEntry()
static ilSessionStatistics::createRawEntry |
( |
|
$a_session_id, |
|
|
|
$a_session_type, |
|
|
|
$a_timestamp, |
|
|
|
$a_user_id |
|
) |
| |
|
static |
Create raw data entry.
- Parameters
-
int | $a_session_id | |
int | $a_session_type | |
int | $a_timestamp | |
int | $a_user_id | |
Definition at line 42 of file class.ilSessionStatistics.php.
References $DIC, and $ilDB.
Referenced by ilSession\_writeData(), and ilSessionControl\checkCurrentSessionIsAllowed().
48 if (!$a_user_id || !$a_session_id || !self::isActive()) {
56 "usr_session_stats_raw",
58 "session_id" => array(
"text", $a_session_id)
61 "type" => array(
"integer", $a_session_type),
62 "start_time" => array(
"integer", $a_timestamp),
63 "user_id" => array(
"integer", $a_user_id)
◆ deleteAggregatedRaw()
static ilSessionStatistics::deleteAggregatedRaw |
( |
|
$a_now | ) |
|
|
staticprotected |
Remove already aggregated raw data.
- Parameters
-
Definition at line 409 of file class.ilSessionStatistics.php.
References $DIC, and $ilDB.
413 $ilDB = $DIC[
'ilDB'];
416 $cut = $a_now - (60 * 60 * 24 * 7);
418 $ilDB->manipulate(
"DELETE FROM usr_session_stats_raw" .
419 " WHERE start_time <= " .
$ilDB->quote($cut,
"integer"));
◆ getActiveSessions()
static ilSessionStatistics::getActiveSessions |
( |
|
$a_from, |
|
|
|
$a_to |
|
) |
| |
|
static |
Get active sessions aggregated data.
- Parameters
-
- Returns
- array
Definition at line 499 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $res, and $row.
Referenced by ilSessionStatisticsGUI\buildData().
503 $ilDB = $DIC[
'ilDB'];
505 $sql =
"SELECT slot_begin, slot_end, active_min, active_max, active_avg," .
507 " FROM usr_session_stats" .
508 " WHERE slot_end > " .
$ilDB->quote($a_from,
"integer") .
509 " AND slot_begin < " .
$ilDB->quote($a_to,
"integer") .
510 " ORDER BY slot_begin";
foreach($_POST as $key=> $value) $res
◆ getCurrentSlot()
static ilSessionStatistics::getCurrentSlot |
( |
|
$a_now | ) |
|
|
staticprotected |
Get next slot to aggregate.
- Parameters
-
- Returns
- array begin, end
Definition at line 133 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $res, and $row.
137 $ilDB = $DIC[
'ilDB'];
140 $sql =
"SELECT MAX(slot_end) previous_slot_end" .
141 " FROM usr_session_stats";
144 $previous_slot_end =
$row[
"previous_slot_end"];
148 if (!$previous_slot_end) {
149 $slot = floor(date(
"i") / self::SLOT_SIZE);
152 $current_slot_begin = mktime(date(
"H", $a_now) - 1, 60 - self::SLOT_SIZE, 0);
156 $current_slot_begin = mktime(date(
"H", $a_now), ($slot - 1) * self::SLOT_SIZE, 0);
159 $current_slot_begin = $previous_slot_end + 1;
162 $current_slot_end = $current_slot_begin + (60 * self::SLOT_SIZE) - 1;
165 if ($current_slot_end < $a_now) {
166 return array($current_slot_begin, $current_slot_end);
foreach($_POST as $key=> $value) $res
◆ getLastAggregation()
static ilSessionStatistics::getLastAggregation |
( |
| ) |
|
|
static |
◆ getLastMaxedOut()
static ilSessionStatistics::getLastMaxedOut |
( |
| ) |
|
|
static |
◆ getLimitForSlot()
static ilSessionStatistics::getLimitForSlot |
( |
|
$a_timestamp | ) |
|
|
static |
Get max session setting for given timestamp.
- Parameters
-
- Returns
- int
Definition at line 544 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $ilSetting, $res, and ilSessionControl\DEFAULT_MAX_COUNT.
548 $ilDB = $DIC[
'ilDB'];
552 $sql =
"SELECT maxval FROM usr_session_log" .
553 " WHERE tstamp <= " .
$ilDB->quote($a_timestamp,
"integer") .
554 " ORDER BY tstamp DESC";
557 if ($val[
"maxval"]) {
558 return (
int) $val[
"maxval"];
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
foreach($_POST as $key=> $value) $res
◆ getMaxedOutDuration()
static ilSessionStatistics::getMaxedOutDuration |
( |
|
$a_from, |
|
|
|
$a_to |
|
) |
| |
|
static |
Get maxed out duration in given timeframe.
- Parameters
-
- Returns
- int seconds
Definition at line 450 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $res, and $row.
Referenced by ilSessionStatisticsGUI\buildData().
454 $ilDB = $DIC[
'ilDB'];
456 $sql =
"SELECT SUM(slot_end-slot_begin) dur FROM usr_session_stats" .
457 " WHERE active_max >= max_sessions" .
458 " AND max_sessions > " .
$ilDB->quote(0,
"integer") .
459 " AND slot_end > " .
$ilDB->quote($a_from,
"integer") .
460 " AND slot_begin < " .
$ilDB->quote($a_to,
"integer");
foreach($_POST as $key=> $value) $res
◆ getNumberOfActiveRawSessions()
static ilSessionStatistics::getNumberOfActiveRawSessions |
( |
|
$a_time | ) |
|
|
staticprotected |
Count number of active sessions at given time.
- Parameters
-
- Returns
- integer
Definition at line 176 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $res, $row, and ilSessionControl\$session_types_controlled.
180 $ilDB = $DIC[
'ilDB'];
182 $sql =
"SELECT COUNT(*) counter FROM usr_session_stats_raw" .
183 " WHERE (end_time IS NULL OR end_time >= " .
$ilDB->quote($a_time,
"integer") .
")" .
184 " AND start_time <= " .
$ilDB->quote($a_time,
"integer") .
188 return $row[
"counter"];
static $session_types_controlled
foreach($_POST as $key=> $value) $res
◆ getNumberOfSessionsByType()
static ilSessionStatistics::getNumberOfSessionsByType |
( |
|
$a_from, |
|
|
|
$a_to |
|
) |
| |
|
static |
Get session counters by type (opened, closed)
- Parameters
-
- Returns
- array
Definition at line 475 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, and $res.
Referenced by ilSessionStatisticsGUI\buildData().
479 $ilDB = $DIC[
'ilDB'];
481 $sql =
"SELECT SUM(opened) opened, SUM(closed_manual) closed_manual," .
482 " SUM(closed_expire) closed_expire, SUM(closed_idle) closed_idle," .
483 " SUM(closed_idle_first) closed_idle_first, SUM(closed_limit) closed_limit," .
484 " SUM(closed_login) closed_login, SUM(closed_misc) closed_misc" .
485 " FROM usr_session_stats" .
486 " WHERE slot_end > " .
$ilDB->quote($a_from,
"integer") .
487 " AND slot_begin < " .
$ilDB->quote($a_to,
"integer");
foreach($_POST as $key=> $value) $res
◆ getRawData()
static ilSessionStatistics::getRawData |
( |
|
$a_begin, |
|
|
|
$a_end |
|
) |
| |
|
staticprotected |
Read raw data for timespan.
- Parameters
-
integer | $a_begin | |
integer | $a_end | |
- Returns
- array
Definition at line 198 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $res, $row, and ilSessionControl\$session_types_controlled.
202 $ilDB = $DIC[
'ilDB'];
204 $sql =
"SELECT start_time,end_time,end_context FROM usr_session_stats_raw" .
205 " WHERE start_time <= " .
$ilDB->quote($a_end,
"integer") .
206 " AND (end_time IS NULL OR end_time >= " .
$ilDB->quote($a_begin,
"integer") .
")" .
208 " ORDER BY start_time";
static $session_types_controlled
foreach($_POST as $key=> $value) $res
◆ isActive()
static ilSessionStatistics::isActive |
( |
| ) |
|
|
static |
◆ updateLimitLog()
static ilSessionStatistics::updateLimitLog |
( |
|
$a_new_value | ) |
|
|
static |
Log max session setting.
- Parameters
-
Definition at line 569 of file class.ilSessionStatistics.php.
References $DIC, $ilDB, $ilSetting, $ilUser, and ilSessionControl\DEFAULT_MAX_COUNT.
Referenced by ilObjUserFolderGUI\saveGeneralSettingsObject().
573 $ilDB = $DIC[
'ilDB'];
577 $new_value = (int) $a_new_value;
580 if ($new_value != $old_value) {
582 "tstamp" => array(
"timestamp", time()),
583 "maxval" => array(
"integer", $new_value),
584 "user_id" => array(
"integer",
$ilUser->getId())
586 $ilDB->insert(
"usr_session_log", $fields);
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
◆ SLOT_SIZE
const ilSessionStatistics::SLOT_SIZE = 15 |
The documentation for this class was generated from the following file: