ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 46 of file LogCleaner.php.

References Sabre\VObject\$debug, $i, $sc, $todelete, and exit.

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

◆ dumpConfig()

sspmod_statistics_LogCleaner::dumpConfig ( )

Definition at line 34 of file LogCleaner.php.

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

◆ store()

sspmod_statistics_LogCleaner::store (   $todelete,
  $outputfile 
)

Definition at line 126 of file LogCleaner.php.

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

127  {
128  echo "Preparing to delete [" .count($todelete) . "] trackids\n";
129 
130  if (!is_dir($this->statdir)) {
131  throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
132  }
133 
134  if (!file_exists($this->inputfile)) {
135  throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
136  }
137 
138  $file = fopen($this->inputfile, 'r');
139 
140  // Open the output file in a way that guarantees that we will not overwrite a random file.
141  if (file_exists($outputfile)) {
142  // Delete existing output file.
143  unlink($outputfile);
144  }
145  $outfile = fopen($outputfile, 'x'); /* Create the output file. */
146 
147  $logparser = new sspmod_statistics_LogParser(
148  $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
149  );
150 
151  $i = 0;
152  // Parse through log file, line by line
153  while (!feof($file)) {
154  $logline = fgets($file, 4096);
155 
156  // Continue if STAT is not found on line.
157  if (!preg_match('/STAT/', $logline)) {
158  continue;
159  }
160  $i++;
161 
162  $content = $logparser->parseContent($logline);
163 
164  if (($i % 10000) == 0) {
165  echo("Read line " . $i . "\n");
166  }
167 
168  $trackid = $content[4];
169  if (in_array($trackid, $todelete, true)) {
170  continue;
171  }
172 
173  fputs($outfile, $logline);
174  }
175  fclose($file);
176  fclose($outfile);
177  }
$todelete
Definition: logcleaner.php:63
$i
Definition: disco.tpl.php:19
+ 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: