$logdate = $logdate2 = 0; if (file_exists($logfile)) { $logdate = filemtime($logfile); } if (file_exists($logfile2)) { $logdate2 = filemtime($logfile2); } $cachedate = $clusterfile->mtime(); if ($cachedate >= $logdate && $cachedate >= $logdate2) { $cachefound = true; $clusterfile->fetch(); } } if (!$cachefound) { $scale = 60; $scalenames = array(60 => 'minute', 60 * 60 => 'hour', 60 * 60 * 24 => 'day'); // *** Parse storage.log files *** $data = ezLogsGrapher::asum(ezLogsGrapher::parseLog($logfile, $scale), ezLogsGrapher::parseLog($logfile2, $scale)); ksort($data); // *** build graph and store it *** $graphname = sysInfoTools::ezpI18ntr('SysInfo', 'files per ' . $scalenames[$scale]); $graph = ezLogsGrapher::graph($data, $graphname, $scale); if ($graph != false) { $clusterfile->fileStoreContents($cachefile, $graph); } else { $errormsg = ezLogsGrapher::lastError(); } } // *** output *** $tpl->setVariable('graphsource', $cachefile); $tpl->setVariable('errormsg', $errormsg);
/** * create graph via ezc/gd2 * @todo verify availability of gd2? * @todo improve layout: col. width, x axis labels, etc... * @todo if zetacomponent graph is not there, create an error image using gd */ static function graph($data, $dataname, $scale = 60) { $content = false; self::$lastError = ''; $times = array_keys($data); $min = $times[0]; $max = end($times); if (!class_exists('ezcGraphBarChart')) { $errormsg = "Error while rendering graph: missing Zetacomponents Graph library"; self::$lastError = $errormsg; eZDebug::writeError($errormsg); return false; } $graph = new ezcGraphBarChart(); $locale = eZLocale::instance(); $graph->title = "From " . $locale->formatShortDateTime($min) . " to " . $locale->formatShortDateTime($max); //$graph->xAxis->label = "From " . $locale->formatShortDateTime( $min ) . " to " . $locale->formatShortDateTime( $max ); $graph->options->font->maxFontSize = 10; $graph->palette = new ezcGraphPaletteEzBlue(); $graph->yAxis->label = $dataname; $graph->yAxis->min = 0; $graph->legend = false; // width of bar charts is not calculated correctly by DateAxis //$graph->xAxis = new ezcGraphChartElementDateAxis(); //$graph->xAxis->interval = $scale; $graph->xAxis = new ezcGraphChartElementNumericAxis(); $graph->xAxis->min = $min - $scale / 2; $graph->xAxis->max = $max + $scale / 2; $graph->xAxis->labelCallback = 'calcChurnLabel'; $graph->data[$dataname] = new ezcGraphArrayDataSet($data); $graph->driver = new ezcGraphGdDriver2(); $graph->driver->options->imageFormat = IMG_JPEG; // pick a font that is delivered along with ezp $graph->options->font = 'design/standard/fonts/arial.ttf'; try { $ok = ob_start(); $graph->render(600, 400, 'php://stdout'); $content = ob_get_clean(); //$clusterfile->fileStoreContents( $cachefile, $content ); } catch (exception $e) { $errormsg = "Error while rendering graph: " . $e->getMessage(); self::$lastError = $errormsg; eZDebug::writeError($errormsg); } return $content; }
} } readfile($logfile); $mdate = gmdate('D, d M Y H:i:s', filemtime($logfile)) . ' GMT'; eZExecution::cleanExit(); } // *** parse rotated log files, if found *** for ($i = eZdebug::maxLogrotateFiles(); $i > 0; $i--) { $archivelog = $logfile . ".{$i}"; if (file_exists($archivelog)) { $data = array_merge($data, ezLogsGrapher::splitLog($archivelog)); //var_dump( $archivelog ); } } // *** Parse log file *** $data = array_reverse(array_merge($data, ezLogsGrapher::splitLog($logfile))); $mdate = gmdate('D, d M Y H:i:s', filemtime($logfile)) . ' GMT'; header("Last-Modified: {$mdate}"); } break; } } if ($Params['viewmode'] == 'raw') { // if we're here it's because desired file was not found // @todo return a 404 error? // It can be either a valid filename but no log yet, or bad filename... } // *** output *** $tpl->setVariable('log', $data); $tpl->setVariable('logfile', $Params['logfile']); $tpl->setVariable('errormsg', $errormsg);
// nb: this dir is calculated the same way as ezlog does $debug = eZDebug::instance(); $logFiles = $debug->logFiles(); foreach ($logFiles as $level => $file) { $logfile = $file[0] . $file[1]; $logname = str_replace('.log', '', $file[1]); if (file_exists($logfile)) { $count = 1; $size = filesize($logfile); $modified = filemtime($logfile); // *** parse rotated log files, if found *** $data = array(); for ($i = eZdebug::maxLogrotateFiles(); $i > 0; $i--) { $archivelog = $logfile . ".{$i}"; if (file_exists($archivelog)) { $data = ezLogsGrapher::asum($data, ezLogsGrapher::parseLog($archivelog)); $size += filesize($archivelog); $count++; } } $logFilesList[$logname] = array('path' => $logfile, 'count' => $count, 'size' => $size, 'modified' => $modified, 'link' => 'sysinfo/logview/' . $logname); } } foreach (scandir('var/log') as $log) { $logfile = "var/log/{$log}"; if (is_file($logfile) && substr($log, -4) == '.log' && !in_array($log, array('error.log', 'warning.log', 'debug.log', 'notice.log', 'strict.log'))) { $logFilesList[$log] = array('path' => $logfile, 'count' => '[1]', 'size' => filesize($logfile), 'modified' => filemtime($logfile), 'link' => 'sysinfo/customlogview/' . str_replace(array('/', '\\'), ':', $logfile)); } } $logDir = eZSys::varDirectory() . '/' . $ini->variable('FileSettings', 'LogDir'); foreach (scandir($logDir) as $log) {