1 <?php
3 class memoryUsageChart extends statChart
4 {
5 var $title = 'Memory usage';
6 var $enableCaching = TRUE;
8 function __construct(&$config)
9 {
10 parent::__construct($config);
11 $this->graphName = get_class();
13 // Generate graph which displays the memory usage over time
14 $this->series = array(
15 'max_mem' => _('Max'),
16 'avg_mem' => _('Avergae'),
17 'min_mem' => _('Min'));
18 $this->dataName = "usagePerInterval";
19 }
22 /*! \brief Generates the line-graph which displays the plugin usage over time.
23 */
24 function render()
25 {
26 // Add series data to dataSet
27 $dataSet = new pData;
28 $max = 0;
29 foreach($this->series as $seriesName => $seriesDesc){
30 if(isset($this->graphData[$this->dataName][$seriesName])){
31 $dataSet->AddPoint($this->graphData[$this->dataName][$seriesName],$seriesName);
32 $dataSet->SetSerieName($seriesDesc,$seriesName);
33 if($max < max($this->graphData[$this->dataName][$seriesName])) $max = max($this->graphData[$this->dataName][$seriesName]);
34 }
35 }
36 $dataSet->AddAllSeries();
37 $dataSet->AddPoint($this->graphData['dates'], 'date');
38 $dataSet->SetAbsciseLabelSerie('date');
40 // Read graph from cache?
41 $pCache = new pCache('/var/spool/gosa/');
42 if($this->enableCaching && $pCache->IsInCache(get_class(),$dataSet->GetData())){
43 $filename = $pCache->GetHash(get_class(),$dataSet->GetData());
44 $filename = '/var/spool/gosa/'.$filename;
45 if(file_exists($filename) && is_readable($filename)){
46 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
47 session::set('statistics::graphFile'.$this->graphID,$filename);
48 return;
49 }
50 }
52 $chart = new pChart(800,230);
53 $chart->setFixedScale(0.0001,($max*1.1));
54 $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);
55 $chart->setGraphArea(50,30,585,200);
56 $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
57 $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);
58 $chart->drawGraphArea(255,255,255,TRUE);
59 $chart->drawGrid(4,TRUE,200,200,200,50);
60 $chart->drawTreshold(0,143,55,72,TRUE,TRUE);
61 $chart->drawTitle(50,22,$this->title,50,50,50,585);
62 $chart->drawLegend(650,30,$dataSet->GetDataDescription(),255,255,255);
64 $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, FALSE);
65 $chart->drawFilledCubicCurve($dataSet->GetData(),$dataSet->GetDataDescription(),.1,50);
67 // Generate new and unique graph id
68 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
69 $file = '/tmp/graph_'.$this->graphID;
70 $chart->Render($file);
71 session::set('statistics::graphFile'.$this->graphID,$file);
72 $pCache->WriteToCache(get_class(),$dataSet->GetData(),$chart);
74 return;
75 }
77 }
78 ?>