5 include_once
"Services/Authentication/classes/class.ilSessionStatistics.php";
40 switch (
$ilCtrl->getNextClass()) {
42 $cmd =
$ilCtrl->getCmd(
"current");
53 $ilTabs = $DIC[
'ilTabs'];
59 $lng->txt(
"trac_current_system_load"),
60 $ilCtrl->getLinkTarget($this,
"current")
64 $lng->txt(
"trac_short_system_load"),
65 $ilCtrl->getLinkTarget($this,
"short")
69 $lng->txt(
"trac_long_system_load"),
70 $ilCtrl->getLinkTarget($this,
"long")
74 $lng->txt(
"trac_periodic_system_load"),
75 $ilCtrl->getLinkTarget($this,
"periodic")
79 protected function current($a_export =
false)
84 $ilToolbar = $DIC[
'ilToolbar'];
86 $ilTabs = $DIC[
'ilTabs'];
89 $ilTabs->activateSubTab(
"current");
92 if (!$_REQUEST[
"smd"]) {
93 $_REQUEST[
"smd"] = self::MODE_TODAY;
95 $mode = (int) $_REQUEST[
"smd"];
98 if (!$_REQUEST[
"smm"]) {
99 $_REQUEST[
"smm"] =
"avg";
101 $measure = (string) $_REQUEST[
"smm"];
105 case self::MODE_TODAY:
106 $time_from = strtotime(
"today");
107 $time_to = strtotime(
"tomorrow") - 1;
108 $scale = self::SCALE_DAY;
111 case self::MODE_LAST_DAY:
113 $time_from = $time_to - 60 * 60 * 24;
114 $scale = self::SCALE_DAY;
117 case self::MODE_LAST_WEEK:
119 $time_from = $time_to - 60 * 60 * 24 * 7;
120 $scale = self::SCALE_WEEK;
123 case self::MODE_LAST_MONTH:
125 $time_from = $time_to - 60 * 60 * 24 * 30;
126 $scale = self::SCALE_MONTH;
130 $mode_options = array(
131 self::MODE_TODAY =>
$lng->txt(
"trac_session_statistics_mode_today"),
132 self::MODE_LAST_DAY =>
$lng->txt(
"trac_session_statistics_mode_last_day"),
133 self::MODE_LAST_WEEK =>
$lng->txt(
"trac_session_statistics_mode_last_week"),
134 self::MODE_LAST_MONTH =>
$lng->txt(
"trac_session_statistics_mode_last_month"));
136 $title =
$lng->txt(
"trac_current_system_load") .
" - " . $mode_options[$mode];
141 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
142 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"current"));
146 $mode_selector->setValue($mode);
147 $ilToolbar->addInputItem($mode_selector,
true);
149 $measure_options = array(
150 "avg" =>
$lng->txt(
"trac_session_active_avg"),
151 "min" =>
$lng->txt(
"trac_session_active_min"),
152 "max" =>
$lng->txt(
"trac_session_active_max"));
155 $measure_selector->
setOptions($measure_options);
156 $measure_selector->setValue($measure);
157 $ilToolbar->addInputItem($measure_selector,
true);
159 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"current");
161 if (
sizeof(
$data[
"active"])) {
162 $ilToolbar->addSeparator();
163 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"currentExport");
179 protected function importDate($a_incoming, $a_default = null)
185 include_once
"Services/Calendar/classes/class.ilCalendarUtil.php";
192 protected function short($a_export =
false)
197 $ilToolbar = $DIC[
'ilToolbar'];
199 $ilTabs = $DIC[
'ilTabs'];
202 $ilTabs->activateSubTab(
"short");
205 $time_to = $this->
importDate($_REQUEST[
"sst"]);
208 if (!$_REQUEST[
"smd"]) {
209 $_REQUEST[
"smd"] = self::MODE_DAY;
211 $mode = (int) $_REQUEST[
"smd"];
214 if (!$_REQUEST[
"smm"]) {
215 $_REQUEST[
"smm"] =
"avg";
217 $measure = (string) $_REQUEST[
"smm"];
221 $time_from = $time_to - 60 * 60 * 24;
222 $scale = self::SCALE_DAY;
225 case self::MODE_WEEK:
226 $time_from = $time_to - 60 * 60 * 24 * 7;
227 $scale = self::SCALE_WEEK;
231 $mode_options = array(
232 self::MODE_DAY =>
$lng->txt(
"trac_session_statistics_mode_day"),
233 self::MODE_WEEK =>
$lng->txt(
"trac_session_statistics_mode_week")
236 $title =
$lng->txt(
"trac_short_system_load") .
" - " . $mode_options[$mode];
241 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
242 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"short"));
246 $ilToolbar->addInputItem($start_selector,
true);
250 $mode_selector->setValue($mode);
251 $ilToolbar->addInputItem($mode_selector,
true);
253 $measure_options = array(
254 "avg" =>
$lng->txt(
"trac_session_active_avg"),
255 "min" =>
$lng->txt(
"trac_session_active_min"),
256 "max" =>
$lng->txt(
"trac_session_active_max"));
259 $measure_selector->
setOptions($measure_options);
260 $measure_selector->setValue($measure);
261 $ilToolbar->addInputItem($measure_selector,
true);
263 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"short");
265 if (
sizeof(
$data[
"active"])) {
266 $ilToolbar->addSeparator();
267 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"shortExport");
281 protected function long($a_export =
false)
286 $ilToolbar = $DIC[
'ilToolbar'];
288 $ilTabs = $DIC[
'ilTabs'];
291 $ilTabs->activateSubTab(
"long");
294 $time_to = $this->
importDate($_REQUEST[
"sst"]);
297 if (!$_REQUEST[
"smd"]) {
298 $_REQUEST[
"smd"] = self::MODE_WEEK;
300 $mode = (int) $_REQUEST[
"smd"];
303 case self::MODE_WEEK:
304 $time_from = $time_to - 60 * 60 * 24 * 7;
305 $scale = self::SCALE_WEEK;
308 case self::MODE_MONTH:
309 $time_from = $time_to - 60 * 60 * 24 * 30;
310 $scale = self::SCALE_MONTH;
313 case self::MODE_YEAR:
314 $time_from = $time_to - 60 * 60 * 24 * 365;
315 $scale = self::SCALE_YEAR;
319 $mode_options = array(
320 self::MODE_WEEK =>
$lng->txt(
"trac_session_statistics_mode_week"),
321 self::MODE_MONTH =>
$lng->txt(
"trac_session_statistics_mode_month"),
322 self::MODE_YEAR =>
$lng->txt(
"trac_session_statistics_mode_year")
325 $title =
$lng->txt(
"trac_long_system_load") .
" - " . $mode_options[$mode];
330 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
331 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"long"));
335 $ilToolbar->addInputItem($start_selector,
true);
339 $mode_selector->setValue($mode);
340 $ilToolbar->addInputItem($mode_selector,
true);
342 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"long");
344 if (
sizeof(
$data[
"active"])) {
345 $ilToolbar->addSeparator();
346 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"longExport");
365 $ilToolbar = $DIC[
'ilToolbar'];
367 $ilTabs = $DIC[
'ilTabs'];
370 $ilTabs->activateSubTab(
"periodic");
373 $time_to = $this->
importDate($_REQUEST[
"sst"]);
376 $time_from = $this->
importDate($_REQUEST[
"sto"], strtotime(
"-7 days"));
379 if ($time_to < $time_from) {
381 $time_to = $time_from;
385 $title =
$lng->txt(
"trac_periodic_system_load");
390 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
391 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"periodic"));
395 $ilToolbar->addInputItem($end_selector,
true);
399 $ilToolbar->addInputItem($start_selector,
true);
401 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"periodic");
403 if (
sizeof(
$data[
"active"])) {
404 $ilToolbar->addSeparator();
405 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"periodicExport");
426 $ilAccess = $DIC[
'ilAccess'];
430 include_once
"Services/Authentication/classes/class.ilSessionControl.php";
433 $control_active = (
$ilSetting->get(
'session_handling_type', 0) == 1);
434 if ($control_active) {
447 $left =
new ilTemplate(
"tpl.session_statistics_left.html",
true,
true,
"Services/Authentication");
449 $left->setVariable(
"CAPTION_CURRENT",
$lng->txt(
"users_online"));
450 $left->setVariable(
"VALUE_CURRENT", $active);
452 $left->setVariable(
"CAPTION_LAST_AGGR",
$lng->txt(
"trac_last_aggregation"));
455 $left->setVariable(
"CAPTION_LAST_MAX",
$lng->txt(
"trac_last_maxed_out_sessions"));
458 $left->setVariable(
"CAPTION_SESSION_CONTROL",
$lng->txt(
"sess_load_dependent_session_handling"));
459 if (!$control_active) {
460 $left->setVariable(
"VALUE_SESSION_CONTROL",
$lng->txt(
"no"));
462 $left->setVariable(
"VALUE_SESSION_CONTROL",
$lng->txt(
"yes"));
464 $left->setCurrentBlock(
"control_details");
466 $left->setVariable(
"CAPTION_SESSION_CONTROL_LIMIT",
$lng->txt(
"session_max_count"));
467 $left->setVariable(
"VALUE_SESSION_CONTROL_LIMIT", $control_max_sessions);
469 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MIN",
$lng->txt(
"session_min_idle"));
470 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MIN", $control_min_idle);
472 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MAX",
$lng->txt(
"session_max_idle"));
473 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MAX", $control_max_idle);
475 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_FIRST",
$lng->txt(
"session_max_idle_after_first_request"));
476 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_FIRST", $control_max_idle_first);
478 $left->parseCurrentBlock();
482 if ($ilAccess->checkAccess(
"write",
"", (
int) $_REQUEST[
"ref_id"])) {
483 $left->setVariable(
"URL_SYNC",
$ilCtrl->getFormAction($this,
"adminSync"));
484 $left->setVariable(
"CMD_SYNC",
"adminSync");
485 $left->setVariable(
"TXT_SYNC",
$lng->txt(
"trac_sync_session_stats"));
491 protected function buildData($a_time_from, $a_time_to, $a_title)
501 $opened = (int) $counters[
"opened"];
502 $closed_limit = (int) $counters[
"closed_limit"];
503 unset($counters[
"opened"]);
504 unset($counters[
"closed_limit"]);
512 $data[
"title"] = $a_title .
" (" .
518 $data[
"maxed_out_time"] = array(
$lng->txt(
"trac_maxed_out_time"), $maxed_out_duration);
519 $data[
"maxed_out_counter"] = array(
$lng->txt(
"trac_maxed_out_counter"), $closed_limit);
520 $data[
"opened"] = array(
$lng->txt(
"trac_sessions_opened"), $opened);
521 $data[
"closed"] = array(
$lng->txt(
"trac_sessions_closed"), array_sum($counters));
522 foreach ($counters as
$type => $counter) {
523 $data[
"closed_details"][] = array(
$lng->txt(
"trac_" .
$type), (int) $counter);
531 protected function render($a_data, $a_scale, $a_measure = null)
537 $center =
new ilTemplate(
"tpl.session_statistics_center.html",
true,
true,
"Services/Authentication");
539 foreach ($a_data as $idx => $item) {
546 case "closed_details":
547 $center->setCurrentBlock(
"closed_details");
548 foreach ($item as $detail) {
549 $center->setVariable(
"CAPTION_CLOSED_DETAILS", $detail[0]);
550 $center->setVariable(
"VALUE_CLOSED_DETAILS", $detail[1]);
551 $center->parseCurrentBlock();
556 $tpl_var = strtoupper($idx);
557 $center->setVariable(
"CAPTION_" . $tpl_var, $item[0]);
558 $center->setVariable(
"VALUE_" . $tpl_var, $item[1]);
563 if ($a_data[
"active"]) {
564 $center->setVariable(
"CHART", $this->
getChart($a_data[
"active"], $a_data[
"title"], $a_scale, $a_measure));
569 return $center->get();
581 protected function getChart($a_data, $a_title, $a_scale = self::SCALE_DAY, $a_measure = null)
587 include_once
"Services/Chart/classes/class.ilChart.php";
589 $chart->setsize(700, 500);
590 $chart->setYAxisToInteger(
true);
596 $a_measure = array(
"min",
"avg",
"max");
597 } elseif (!is_array($a_measure)) {
598 $a_measure = array($a_measure);
601 $colors_map = array(
"min" =>
"#00cc00",
605 $colors = $act_line = array();
606 foreach ($a_measure as $measure) {
608 $act_line[$measure]->setLineSteps(
true);
609 $act_line[$measure]->setLabel(
$lng->txt(
"trac_session_active_" . $measure));
610 $colors[] = $colors_map[$measure];
613 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
615 $max_line->setLabel(
$lng->txt(
"session_max_count"));
616 $colors[] =
"#cc0000";
619 $chart->setColors($colors);
624 $scale = ceil(
sizeof($chart_data) / 5);
626 foreach ($chart_data as $idx => $item) {
627 $date = $item[
"slot_begin"];
629 if ($a_scale == self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale))) {
631 case self::SCALE_DAY:
632 $labels[$date] = date(
"H:i", $date);
635 case self::SCALE_WEEK:
636 $labels[$date] = date(
"d.m. H", $date) .
"h";
639 case self::SCALE_MONTH:
640 $labels[$date] = date(
"d.m.", $date);
643 case self::SCALE_YEAR:
644 $labels[$date] = date(
"Y-m", $date);
647 case self::SCALE_PERIODIC_WEEK:
648 $day = substr($date, 0, 1);
649 $hour = substr($date, 1, 2);
650 $min = substr($date, 3, 2);
653 $day_value = ($day - 1) * 60 * 60 * 24;
654 $date = $day_value + $hour * 60 * 60 + $min * 60;
657 if ($hour != $old_hour && $hour && $hour % 6 == 0) {
658 $labels[$date] = $hour;
662 if ($day != $old_day) {
670 foreach ($a_measure as $measure) {
671 $value = (int) $item[
"active_" . $measure];
672 $act_line[$measure]->addPoint($date, $value);
675 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
676 $max_line->addPoint($date, (
int) $item[
"max_sessions"]);
680 foreach ($act_line as $line) {
681 $chart->addData($line);
683 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
684 $chart->addData($max_line);
687 $chart->setTicks($labels, null,
true);
689 return $chart->getHTML();
696 case self::SCALE_DAY:
700 case self::SCALE_WEEK:
706 foreach ($a_data as $item) {
707 $date_parts = getdate($item[
"slot_begin"]);
711 case self::SCALE_MONTH:
713 $slot = mktime($date_parts[
"hours"], 0, 0, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
716 case self::SCALE_YEAR:
718 $slot = mktime(0, 0, 1, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
721 case self::SCALE_PERIODIC_WEEK:
723 $day = $date_parts[
"wday"];
727 $slot = $day . date(
"His", $item[
"slot_begin"]);
732 foreach ($item as
$id => $value) {
733 switch (substr(
$id, -3)) {
735 if (!$tmp[$slot][
$id] || $value < $tmp[$slot][
$id]) {
736 $tmp[$slot][
$id] = $value;
741 if (!$tmp[$slot][$id] || $value > $tmp[$slot][$id]) {
742 $tmp[$slot][
$id] = $value;
747 $tmp[$slot][
$id][] = $value;
753 foreach ($tmp as $slot => $attr) {
754 $tmp[$slot][
"active_avg"] = (int) round(array_sum($attr[
"active_avg"]) /
sizeof($attr[
"active_avg"]));
755 $tmp[$slot][
"slot_begin"] = $slot;
758 return array_values($tmp);
773 ilUtil::sendSuccess(
$lng->txt(
"trac_sync_session_stats_success"),
true);
782 $ilClientIniFile = $DIC[
'ilClientIniFile'];
786 include_once
'./Services/Link/classes/class.ilLink.php';
788 include_once
"./Services/Utilities/classes/class.ilCSVWriter.php";
790 $csv->setSeparator(
";");
796 $lng->txt(
"trac_name_of_installation") => $ilClientIniFile->readVariable(
'client',
'name'),
798 $lng->txt(
"trac_report_owner") =>
$ilUser->getFullName(),
800 foreach ($a_data as $idx => $item) {
803 $meta[
$lng->txt(
"title")] = $item;
810 case "closed_details":
811 foreach ($item as $detail) {
812 $meta[$a_data[
"closed"][0] .
" - " . $detail[0]] = $detail[1];
817 $meta[$item[0]] = $item[1];
821 foreach ($meta as $caption => $value) {
822 $csv->addColumn(strip_tags($caption));
823 $csv->addColumn(strip_tags($value));
834 $first = array_keys(array_shift($first));
835 foreach ($first as $column) {
837 if ($a_scale == self::SCALE_PERIODIC_WEEK && $column ==
"slot_begin") {
838 $csv->addColumn(
"weekday");
839 $csv->addColumn(
"time");
841 $csv->addColumn(strip_tags($column));
847 foreach ($aggr_data as
$row) {
848 foreach ($row as $column => $value) {
849 if (is_array($value)) {
850 $value = implode(
', ', $value);
855 if ($a_scale == self::SCALE_PERIODIC_WEEK) {
857 $value = substr($value, 1, 2) .
":" . substr($value, 3, 2);
864 $value = date(
"d.m.Y H:i", $value);
867 $csv->addColumn(strip_tags($value));
873 $filename .=
"session_statistics_" . date(
"Ymd", $now) .
".csv";
874 header(
"Content-type: text/comma-separated-values");
875 header(
"Content-Disposition: attachment; filename=\"" .
$filename .
"\"");
876 header(
"Expires: 0");
877 header(
"Cache-Control: must-revalidate, post-check=0,pre-check=0");
878 header(
"Pragma: public");
879 echo $csv->getCSVString();
Class ilSessionStatisticsGUI.
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
exportCSV(array $a_data, $a_scale)
static getMaxedOutDuration($a_from, $a_to)
Get maxed out duration in given timeframe.
Helper class to generate CSV files.
static _numericDayToString($a_day, $a_long=true)
get
const SCALE_PERIODIC_WEEK
static $session_types_controlled
if(!array_key_exists('StateId', $_REQUEST)) $id
static setUseRelativeDates($a_status)
set use relative dates
static getNumberOfSessionsByType($a_from, $a_to)
Get session counters by type (opened, closed)
static _destroyExpiredSessions()
Destroy expired sessions.
importDate($a_incoming, $a_default=null)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
render($a_data, $a_scale, $a_measure=null)
static getLastAggregation()
Get timestamp of last aggregation.
special template class to simplify handling of ITX/PEAR
static getExistingSessionCount(array $a_types)
returns number of valid sessions relating to given session types
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
adaptDataToScale($a_scale, array $a_data)
getChart($a_data, $a_title, $a_scale=self::SCALE_DAY, $a_measure=null)
Build chart for active sessions.
periodic($a_export=false)
static getLastMaxedOut()
Get latest slot during which sessions were maxed out.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
buildData($a_time_from, $a_time_to, $a_title)
static getInstanceByType($a_type, $a_id)
Get type instance.
const DEFAULT_MAX_IDLE_AFTER_FIRST_REQUEST
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static getActiveSessions($a_from, $a_to)
Get active sessions aggregated data.