ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_statistics_LogCleaner Class Reference
+ Collaboration diagram for sspmod_statistics_LogCleaner:

Public Member Functions

 __construct ($inputfile=null)
 Constructor. More...
 
 dumpConfig ()
 
 clean ($debug=false)
 
 store ($todelete, $outputfile)
 

Private Attributes

 $statconfig
 
 $statdir
 
 $inputfile
 
 $statrules
 
 $offset
 

Detailed Description

Definition at line 6 of file LogCleaner.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_statistics_LogCleaner::__construct (   $inputfile = null)

Constructor.

Definition at line 17 of file LogCleaner.php.

References $inputfile, and SimpleSAML_Configuration\getConfig().

18  {
19  $this->statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
20 
21  $this->statdir = $this->statconfig->getValue('statdir');
22  $this->inputfile = $this->statconfig->getValue('inputfile');
23  $this->statrules = $this->statconfig->getValue('statrules');
24  $this->offset = $this->statconfig->getValue('offset', 0);
25 
26  if (isset($inputfile)) {
27  $this->inputfile = $inputfile;
28  }
29  }
static getConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
+ Here is the call graph for this function:

Member Function Documentation

◆ clean()

sspmod_statistics_LogCleaner::clean (   $debug = false)

Definition at line 38 of file LogCleaner.php.

References $action, $debug, $file, $i, $results, $sc, $todelete, array, date, and exit.

38  {
39  if (!is_dir($this->statdir)) {
40  throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
41  }
42 
43  if (!file_exists($this->inputfile)) {
44  throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
45  }
46 
47  $file = fopen($this->inputfile, 'r');
48 
49  $logparser = new sspmod_statistics_LogParser(
50  $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
51  );
52  $datehandler = new sspmod_statistics_DateHandler($this->offset);
53 
54  $results = array();
55  $sessioncounter = array();
56 
57  $i = 0;
58  // Parse through log file, line by line
59  while (!feof($file)) {
60  $logline = fgets($file, 4096);
61 
62  // Continue if STAT is not found on line
63  if (!preg_match('/STAT/', $logline)) {
64  continue;
65  }
66  $i++;
67 
68  // Parse log, and extract epoch time and rest of content.
69  $epoch = $logparser->parseEpoch($logline);
70  $content = $logparser->parseContent($logline);
71  $action = trim($content[5]);
72 
73  if (($i % 10000) == 0) {
74  echo("Read line " . $i . "\n");
75  }
76 
77  $trackid = $content[4];
78 
79  if (!isset($sessioncounter[$trackid])) {
80  $sessioncounter[$trackid] = 0;
81  }
82  $sessioncounter[$trackid]++;
83 
84  if ($debug) {
85  echo("----------------------------------------\n");
86  echo('Log line: ' . $logline . "\n");
87  echo('Date parse [' . substr($logline, 0, $this->statconfig->getValue('datelength', 15)) . '] to [' . date(DATE_RFC822, $epoch) . ']' . "\n");
88  echo htmlentities(print_r($content, true));
89  if ($i >= 13) {
90  exit;
91  }
92  }
93  }
94 
95  $histogram = array();
96  foreach ($sessioncounter as $trackid => $sc) {
97  if (!isset($histogram[$sc])) {
98  $histogram[$sc] = 0;
99  }
100  $histogram[$sc]++;
101  }
102  ksort($histogram);
103 
104  $todelete = array();
105  foreach ($sessioncounter as $trackid => $sc) {
106  if ($sc > 200) {
107  $todelete[] = $trackid;
108  }
109  }
110 
111  return $todelete;
112  }
$action
$todelete
Definition: logcleaner.php:63
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
$debug
Definition: loganalyzer.php:16
$results
Definition: svg-scanner.php:47
$i
Definition: disco.tpl.php:19
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

◆ dumpConfig()

sspmod_statistics_LogCleaner::dumpConfig ( )

Definition at line 31 of file LogCleaner.php.

32  {
33  echo 'Statistics directory : ' . $this->statdir . "\n";
34  echo 'Input file : ' . $this->inputfile . "\n";
35  echo 'Offset : ' . $this->offset . "\n";
36  }

◆ store()

sspmod_statistics_LogCleaner::store (   $todelete,
  $outputfile 
)

Definition at line 114 of file LogCleaner.php.

References $action, $file, $i, $todelete, and sspmod_statistics_LogParser\parseContent().

115  {
116  echo "Preparing to delete [" .count($todelete) . "] trackids\n";
117 
118  if (!is_dir($this->statdir)) {
119  throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
120  }
121 
122  if (!file_exists($this->inputfile)) {
123  throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
124  }
125 
126  $file = fopen($this->inputfile, 'r');
127 
128  // Open the output file in a way that guarantees that we will not overwrite a random file.
129  if (file_exists($outputfile)) {
130  // Delete existing output file.
131  unlink($outputfile);
132  }
133  $outfile = fopen($outputfile, 'x'); /* Create the output file. */
134 
135  $logparser = new sspmod_statistics_LogParser(
136  $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
137  );
138 
139  $i = 0;
140  // Parse through log file, line by line
141  while (!feof($file)) {
142  $logline = fgets($file, 4096);
143 
144  // Continue if STAT is not found on line.
145  if (!preg_match('/STAT/', $logline)) {
146  continue;
147  }
148  $i++;
149 
150  $content = $logparser->parseContent($logline);
151  $action = trim($content[5]);
152 
153  if (($i % 10000) == 0) {
154  echo("Read line " . $i . "\n");
155  }
156 
157  $trackid = $content[4];
158  if (in_array($trackid, $todelete, true)) {
159  continue;
160  }
161 
162  fputs($outfile, $logline);
163  }
164  fclose($file);
165  fclose($outfile);
166  }
$action
$todelete
Definition: logcleaner.php:63
$i
Definition: disco.tpl.php:19
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $inputfile

sspmod_statistics_LogCleaner::$inputfile
private

Definition at line 10 of file LogCleaner.php.

Referenced by __construct().

◆ $offset

sspmod_statistics_LogCleaner::$offset
private

Definition at line 12 of file LogCleaner.php.

◆ $statconfig

sspmod_statistics_LogCleaner::$statconfig
private

Definition at line 8 of file LogCleaner.php.

◆ $statdir

sspmod_statistics_LogCleaner::$statdir
private

Definition at line 9 of file LogCleaner.php.

◆ $statrules

sspmod_statistics_LogCleaner::$statrules
private

Definition at line 11 of file LogCleaner.php.


The documentation for this class was generated from the following file: