25 $this->statdir = $this->statconfig->getValue(
'statdir');
26 $this->inputfile = $this->statconfig->getValue(
'inputfile');
27 $this->statrules = $this->statconfig->getValue(
'statrules');
28 $this->timeres = $this->statconfig->getValue(
'timeres');
29 $this->offset = $this->statconfig->getValue(
'offset', 0);
30 $this->metadata = null;
32 $this->starttime =
time();
37 echo
'Statistics directory : ' . $this->statdir .
"\n";
38 echo
'Input file : ' . $this->inputfile .
"\n";
39 echo
'Offset : ' . $this->offset .
"\n";
44 echo
'Memory usage : ' . number_format(memory_get_usage() / (1024*1024), 2) .
" MB\n";
49 $filename = $this->statdir .
'/.stat.metadata';
65 $this->metadata[
'memory'] = memory_get_usage();
66 $this->metadata[
'lastrun'] =
time();
68 $filename = $this->statdir .
'/.stat.metadata';
69 file_put_contents(
$filename, serialize($this->metadata), LOCK_EX);
75 if (!is_dir($this->statdir)) {
76 throw new Exception(
'Statistics module: output dir do not exists [' . $this->statdir .
']');
79 if (!file_exists($this->inputfile)) {
80 throw new Exception(
'Statistics module: input file do not exists [' . $this->inputfile .
']');
83 $file = fopen($this->inputfile,
'r');
85 if (
$file ===
false) {
86 throw new Exception(
'Statistics module: unable to open file [' . $this->inputfile .
']');
90 $this->statconfig->getValue(
'datestart', 0), $this->statconfig->getValue(
'datelength', 15), $this->statconfig->getValue(
'offsetspan', 44)
101 if (isset($this->metadata)) {
102 $notBefore = $this->metadata[
'notBefore'];
103 $lastlinehash = $this->metadata[
'lastlinehash'];
106 $lastlogline =
'sdfsdf';
107 $lastlineflip =
false;
112 while (!feof(
$file)) {
113 $logline = fgets(
$file, 4096);
116 if (!preg_match(
'/STAT/', $logline)) {
121 $lastlogline = $logline;
124 $epoch = $logparser->parseEpoch($logline);
125 $content = $logparser->parseContent($logline);
128 if ($this->fromcmdline && (
$i % 10000) == 0) {
129 echo(
"Read line " .
$i .
"\n");
133 echo(
"----------------------------------------\n");
134 echo(
'Log line: ' . $logline .
"\n");
135 echo(
'Date parse [' . substr($logline, 0, $this->statconfig->getValue(
'datelength', 15)) .
'] to [' .
date(DATE_RFC822, $epoch) .
']' .
"\n");
136 echo htmlentities(print_r($content,
true));
142 if ($epoch > $lastRead) {
146 if ($epoch === $notBefore) {
147 if (!$lastlineflip) {
148 if (sha1($logline) === $lastlinehash) {
149 $lastlineflip =
true;
155 if ($epoch < $notBefore) {
160 foreach ($this->statrules as $rulename =>
$rule) {
163 if (array_key_exists(
'type',
$rule)) {
167 if (
$type !==
'aggregate') {
171 foreach ($this->timeres AS $tres => $tresconfig ) {
173 if (isset($tresconfig[
'customDateHandler'])) {
174 $dh = $tresconfig[
'customDateHandler'];
177 $timeslot = $datehandler[
'default']->toSlot($epoch, $tresconfig[
'slot']);
178 $fileslot = $datehandler[$dh]->toSlot($epoch, $tresconfig[
'fileslot']);
184 $difcol = self::getDifCol($content,
$rule[
'col']);
198 $this->metadata[
'notBefore'] = $lastRead;
199 $this->metadata[
'lastline'] = $lastlogline;
200 $this->metadata[
'lastlinehash'] = sha1($lastlogline);
206 if (is_int($colrule)) {
207 return trim($content[$colrule]);
208 } elseif (is_array($colrule)) {
210 foreach ($colrule as $cr) {
211 $difcols[] = trim($content[$cr]);
213 return join(
'|', $difcols);
222 foreach ($previous as $slot => $dataarray) {
223 if (!array_key_exists($slot,
$dataset)) {
233 foreach ($newdata as $slot => $dataarray) {
234 if (!array_key_exists($slot,
$dataset)) {
249 $datehandler =
array(
255 foreach (
$results as $rulename => $timeresdata) {
257 foreach ($timeresdata as $tres => $resres) {
259 if (isset($this->timeres[$tres][
'customDateHandler'])) {
260 $dh = $this->timeres[$tres][
'customDateHandler'];
263 $filenos = array_keys($resres);
264 $lastfile = $filenos[count($filenos) - 1];
267 foreach ($resres as $fileno => $fileres) {
269 $slotlist = array_keys($fileres);
272 $maxslot = $slotlist[count($slotlist) - 1];
275 $start = (int)$datehandler[
'default']->toSlot(
276 $datehandler[$dh]->fromSlot($fileno, $this->timeres[$tres][
'fileslot']),
277 $this->timeres[$tres][
'slot']
279 $end = (int)$datehandler[
'default']->toSlot(
280 $datehandler[$dh]->fromSlot($fileno+1, $this->timeres[$tres][
'fileslot']),
281 $this->timeres[$tres][
'slot']
285 $filledresult =
array();
286 for ($slot = $start; $slot <
$end; $slot++) {
287 if (array_key_exists($slot, $fileres)) {
288 $filledresult[$slot] = $fileres[$slot];
290 if ($lastfile == $fileno && $slot > $maxslot) {
291 $filledresult[$slot] =
array(
'_' => null);
293 $filledresult[$slot] =
array(
'_' => 0);
298 $filename = $this->statdir .
'/' . $rulename .
'-' . $tres .
'-' . $fileno .
'.stat';
300 $previousData = unserialize(file_get_contents(
$filename));
301 $filledresult = $this->
cummulateData($previousData, $filledresult);
305 file_put_contents(
$filename, serialize($filledresult), LOCK_EX);
cummulateData($previous, $newdata)
__construct($fromcmdline=false)
Constructor.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static getConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
Create styles array
The data for the language used.
static getDifCol($content, $colrule)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file