From cfa9de6a259571b56484441580f9c5e99e1eb4ab Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 24 Aug 2010 15:17:16 +0000 Subject: [PATCH] Added some more charts git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19444 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../chartClasses/class_pieChart1.inc | 92 +++++++++++++++++++ .../chartClasses/class_pieChart2.inc | 16 ++++ .../generic/statistics/class_statistics.inc | 61 +----------- .../plugins/generic/statistics/statistics.tpl | 23 +---- 4 files changed, 114 insertions(+), 78 deletions(-) create mode 100644 gosa-core/plugins/generic/statistics/chartClasses/class_pieChart1.inc create mode 100644 gosa-core/plugins/generic/statistics/chartClasses/class_pieChart2.inc diff --git a/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart1.inc b/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart1.inc new file mode 100644 index 000000000..4fd22194f --- /dev/null +++ b/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart1.inc @@ -0,0 +1,92 @@ +graphName = get_class(); + } + + /*! \brief Generate the pie-chart which displays the overall-plugin-usage + */ + function render() + { + // Do nothing, if we've no data. + $data = array(); + if(isset($this->graphData[$this->keyName]) && count($this->graphData[$this->keyName])){ + $data = $this->graphData[$this->keyName]; + } + + // Sort data by usage count and slice array to get + // the eight most used categories + arsort($data); + + // Detect max value and throw out entries less than 1% + // the will else be unreadable + $max = max($data); + $pos = 0; + foreach($data as $key => $count){ + if($pos >=7 || ($count / $max)*100 < 1) break; + $pos ++; + } + + $dataRes = array_slice($data,0,$pos); + + // Get the rest of categories and combine them 'others' + $theRest = array_slice($data,$pos); + $dataRes['remaining'] = array_sum($theRest); + + // Try to find a translation for the given category names + $values = array_values($dataRes); + $keys = array_keys($dataRes); + foreach($keys as $id => $cat){ + $keys[$id] = $this->getCategoryTranslation($cat); + } + + // Dataset definition + $dataSet = new pData; + $dataSet->AddPoint($values,"Serie1"); + $dataSet->AddAllSeries(); + $dataSet->AddPoint($keys,"Serie2"); + $dataSet->SetAbsciseLabelSerie("Serie2"); + + // 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; + } + } + + // Set graph area + $x = 400; + $y = 200; + + // Initialise the graph + $chart = new pChart($x,$y); + $chart->setFontProperties($this->font,10); + if(count($data)) { + $chart->drawPieGraph($dataSet->GetData(),$dataSet->GetDataDescription(),($x/3),($y/2)-10,($y/2),PIE_PERCENTAGE,TRUE,50,20,6); + } + $chart->drawPieLegend(($x/3*2),15,$dataSet->GetData(),$dataSet->GetDataDescription(),255,255,255); + + // Store graph data + $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); + } +} +?> diff --git a/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart2.inc b/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart2.inc new file mode 100644 index 000000000..04dc1aedf --- /dev/null +++ b/gosa-core/plugins/generic/statistics/chartClasses/class_pieChart2.inc @@ -0,0 +1,16 @@ +graphName = get_class(); + } +} +?> diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index 0794bb425..25f9259b3 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -40,6 +40,11 @@ class statistics extends plugin $this->graphs[] = new categoryActionsOverTime($config); $this->graphs[] = new memoryUsageChart($config); + $this->graphs[] = new cpuLoadChart($config); + $this->graphs[] = new renderTimeChart($config); + $this->graphs[] = new durationTimeChart($config); + $this->graphs[] = new pieChart1($config); + $this->graphs[] = new pieChart2($config); // Init start and stop times for graph 1 $this->graph1DatePicker1 = date('d.m.Y', time() - 14 * 24 * 60 *60); @@ -351,28 +356,11 @@ class statistics extends plugin if(!count($gData)){ return; } - $this->generatePieGraph($gData['actionsPerCategory'], 1, _("Plugin usage")); - $this->generatePieGraph($gData['actionsPerPluginAction'], 7,_("Actions")); - $curGraph = $this->graphs[$this->selectedGraphType]; $curGraph->setGraphData($gData); $curGraph->render(); # $this->generateActionsGraph($gData); -# // Generate graph which displays the memory usage over time -# $series = array( -# 'max_mem' => _('Max'), -# 'avg_mem' => _('Avergae'), -# 'min_mem' => _('Min')); -# $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("Memory usage"),3); -# -# // Generate graph which displays the cpu load over time -# $series = array( -# 'max_load' => _('Max'), -# 'avg_load' => _('Avergae'), -# 'min_load' => _('Min')); -# $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("CPU load"),4); -# # // Generate graph which displays the render time # $series = array( # 'max_render' => _('Max'), @@ -390,45 +378,6 @@ class statistics extends plugin - /*! \brief Generates a graph about system informations. - */ - function generateSystemStatsGraph($gData, $key = "", $series= array(), $title = "", $gID=0 ) - { - // Add series data to dataSet - $dataSet = new pData; - $max = 0; - foreach($series as $seriesName => $seriesDesc){ - if(isset($gData[$key][$seriesName])){ - $dataSet->AddPoint($gData[$key][$seriesName],$seriesName); - $dataSet->SetSerieName($seriesDesc,$seriesName); - if($max < max($gData[$key][$seriesName])) $max = max($gData[$key][$seriesName]); - } - } - $dataSet->AddAllSeries(); - $dataSet->AddPoint($gData['dates'], 'date'); - $dataSet->SetAbsciseLabelSerie('date'); - - $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,$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); - - $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)); - $file = '/tmp/graph_'.$this->graphIDs[$gID]; - $chart->Render($file); - session::set('statistics::graphFile'.$this->graphIDs[$gID],$file); - } - /*! \brief Generate the pie-chart which displays the overall-plugin-usage */ diff --git a/gosa-core/plugins/generic/statistics/statistics.tpl b/gosa-core/plugins/generic/statistics/statistics.tpl index 50801a60f..2c26ab0fe 100644 --- a/gosa-core/plugins/generic/statistics/statistics.tpl +++ b/gosa-core/plugins/generic/statistics/statistics.tpl @@ -70,11 +70,9 @@ {if isset($curGraphID) && $curGraphID} - - {html_options options=$availableGraphs selected=$selectedGraphType} -
@@ -90,23 +88,4 @@
{/if} - - - {if isset($graphIDs.3) && $graphIDs.3} - -
- {/if} - {if isset($graphIDs.4) && $graphIDs.4} - -
- {/if} - {if isset($graphIDs.5) && $graphIDs.5} - -
- {/if} - {if isset($graphIDs.6) && $graphIDs.6} - -
- {/if} - {/if} -- 2.30.2