From 37bef713457f4cd425aa9e68fdcc386cec260d3a Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 24 Aug 2010 14:57:44 +0000 Subject: [PATCH] Added memory usage chart git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19442 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../chartClasses/class_memoryUsageChart.inc | 78 +++++++++++++++++++ .../generic/statistics/class_statistics.inc | 2 +- .../plugins/generic/statistics/statistics.tpl | 2 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc 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 index 000000000..a3f891486 --- /dev/null +++ b/gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc @@ -0,0 +1,78 @@ +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; + } + +} +?> diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index 7774bbb73..0794bb425 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -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); diff --git a/gosa-core/plugins/generic/statistics/statistics.tpl b/gosa-core/plugins/generic/statistics/statistics.tpl index c88910478..50801a60f 100644 --- a/gosa-core/plugins/generic/statistics/statistics.tpl +++ b/gosa-core/plugins/generic/statistics/statistics.tpl @@ -71,7 +71,7 @@ {if isset($curGraphID) && $curGraphID} - {html_options options=$availableGraphs selected=$selectedGraphType} -- 2.30.2