Ejemplo n.º 1
0
    $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);
Ejemplo n.º 2
0
 /**
  * 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;
 }