Code

Added memory usage chart
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Aug 2010 14:57:44 +0000 (14:57 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Aug 2010 14:57:44 +0000 (14:57 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19442 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc [new file with mode: 0644]
gosa-core/plugins/generic/statistics/class_statistics.inc
gosa-core/plugins/generic/statistics/statistics.tpl

diff --git a/gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc b/gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc
new file mode 100644 (file)
index 0000000..a3f8914
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+class memoryUsageChart extends statChart
+{
+    var $title = 'Memory usage';
+    var $enableCaching = TRUE;
+
+    function __construct(&$config)
+    {
+        parent::__construct($config);
+        $this->graphName = get_class();
+
+        // Generate graph which displays the memory usage over time
+        $this->series = array(
+                'max_mem' => _('Max'),
+                'avg_mem' => _('Avergae'),
+                'min_mem' => _('Min'));
+        $this->dataName = "usagePerInterval";
+    }
+
+
+    /*! \brief  Generates the line-graph which displays the plugin usage over time.
+     */ 
+    function render()
+    {
+        // Add series data to dataSet        
+        $dataSet = new pData;  
+        $max = 0;
+        foreach($this->series as $seriesName => $seriesDesc){
+            if(isset($this->graphData[$this->dataName][$seriesName])){
+                $dataSet->AddPoint($this->graphData[$this->dataName][$seriesName],$seriesName);
+                $dataSet->SetSerieName($seriesDesc,$seriesName);
+                if($max < max($this->graphData[$this->dataName][$seriesName])) $max = max($this->graphData[$this->dataName][$seriesName]);
+            }
+        }
+        $dataSet->AddAllSeries();  
+        $dataSet->AddPoint($this->graphData['dates'], 'date');
+        $dataSet->SetAbsciseLabelSerie('date');  
+        
+        // Read graph from cache?
+        $pCache = new pCache('/var/spool/gosa/');
+        if($this->enableCaching && $pCache->IsInCache(get_class(),$dataSet->GetData())){
+            $filename =  $pCache->GetHash(get_class(),$dataSet->GetData());
+            $filename = '/var/spool/gosa/'.$filename;    
+            if(file_exists($filename) && is_readable($filename)){
+                $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
+                session::set('statistics::graphFile'.$this->graphID,$filename);
+                return;
+            }
+        }
+
+        $chart = new pChart(800,230);  
+        $chart->setFixedScale(0.0001,($max*1.1));  
+        $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);  
+        $chart->setGraphArea(50,30,585,200);  
+        $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);  
+        $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);  
+        $chart->drawGraphArea(255,255,255,TRUE);  
+        $chart->drawGrid(4,TRUE,200,200,200,50);  
+        $chart->drawTreshold(0,143,55,72,TRUE,TRUE);  
+        $chart->drawTitle(50,22,$this->title,50,50,50,585);  
+        $chart->drawLegend(650,30,$dataSet->GetDataDescription(),255,255,255);  
+
+        $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, FALSE);
+        $chart->drawFilledCubicCurve($dataSet->GetData(),$dataSet->GetDataDescription(),.1,50); 
+
+        // Generate new and unique graph id
+        $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
+        $file = '/tmp/graph_'.$this->graphID;
+        $chart->Render($file);
+        session::set('statistics::graphFile'.$this->graphID,$file);
+        $pCache->WriteToCache(get_class(),$dataSet->GetData(),$chart);   
+
+        return;
+    }
+
+}
+?>
index 7774bbb73c55c6fd0f0c1480262dc8206cb64997..0794bb42574a281166ef4b1e1d30c20818449c31 100644 (file)
@@ -39,7 +39,7 @@ class statistics extends plugin
         plugin::plugin($config, NULL);
 
         $this->graphs[] = new categoryActionsOverTime($config); 
-        $this->graphs[] = new testChart($config); 
+        $this->graphs[] = new memoryUsageChart($config); 
 
         // Init start and stop times for graph 1
         $this->graph1DatePicker1 = date('d.m.Y', time() - 14 * 24 * 60 *60);
index c889104787b1f09afca78168ad999024a901a668..50801a60ff3483f3d4c4a838b738e4483f72ae34 100644 (file)
@@ -71,7 +71,7 @@
 
     {if isset($curGraphID) && $curGraphID}
     
-        <select name='selectedGraphType'>
+        <select name='selectedGraphType' onChange="document.mainform.submit();">
             {html_options options=$availableGraphs selected=$selectedGraphType}
         </select>