From fda2ac939949ec8f3b3209552e40b9ad54a46b6f Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Thu, 2 Dec 2010 14:23:19 +0100 Subject: [PATCH] bacula-web: Improved bgraph classe and new status job graph in dashboard - New function GetJobsStatistics() in bweb classe - New graph in main dashboard with last 24 hours job status - Improved PHP code in bgraph classe --- gui/bacula-web/bgraph.inc.php | 8 +++- gui/bacula-web/bweb.inc.php | 73 ++++++++++++++++++++++++++++- gui/bacula-web/graph.png | Bin 0 -> 2229 bytes gui/bacula-web/index.php | 17 ++++--- gui/bacula-web/templates/index.tpl | 22 +++++---- 5 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 gui/bacula-web/graph.png diff --git a/gui/bacula-web/bgraph.inc.php b/gui/bacula-web/bgraph.inc.php index 9ea23f3b3d..9f0fb218a3 100644 --- a/gui/bacula-web/bgraph.inc.php +++ b/gui/bacula-web/bgraph.inc.php @@ -84,8 +84,14 @@ class BGraph{ // Image border $this->plot->SetImageBorderType( 'none' ); + // Plot area (calculated regarding the width and height of the graph) + if( $this->type == 'pie' ) + $this->plot->SetPlotAreaPixels( 10, 10, ($this->width / 2), $this->height-10 ); + + // Legend position (calculated regarding the width and height of the graph) + $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 ); - // Labels position + // Labels scale position if( $this->type == 'pie' ) $this->plot->SetLabelScalePosition( 0.2 ); diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 60f9be11a4..a201188c9b 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -371,8 +371,6 @@ class Bweb extends DB { public function GetLastErrorJobs( $delay = LAST_DAY ) { $query = ""; - $start_date = ""; - $end_date = ""; // Interval calculation $end_date = mktime(); @@ -455,7 +453,78 @@ class Bweb extends DB { } } } + + // Return Jobs statistics for a specific interval such as + // - Completed jobs number + // - Failed jobs number + // - Waiting jobs number + // The returned values will be used by a Bgraph classe + public function GetJobsStatistics( $type = 'completed', $delay = LAST_DAY ) + { + $query = ""; + $where = ""; + $jobs = ""; + $label = ""; + $res = ""; + + // Interval calculation + $end_date = mktime(); + $start_date = $end_date - $delay; + + $start_date = date( "Y-m-d H:m:s", $start_date ); + $end_date = date( "Y-m-d H:m:s", $end_date ); + + // Job status + switch( $type ) + { + case 'completed': + $where = "AND JobStatus = 'T' "; + $label = "Completed"; + break; + case 'completed_errors': + $where = "AND JobStatus = 'E' "; + $label = "Completed with errors"; + break; + case 'failed': + $where = "AND JobStatus = 'f' "; + $label = "Failed"; + break; + case 'waiting': + $where = "AND JobStatus IN ('F','S','M','m','s','j','c','d','t') "; + $label = "Waiting"; + break; + case 'created': + $where = "AND JobStatus = 'C' "; + $label = "Created but not running"; + break; + case 'running': + $where = "AND JobStatus = 'R' "; + $label = "Running"; + break; + case 'error': + $where = "AND JobStatus IN ('e','f') "; + $label = "Errors"; + break; + } + $query = 'SELECT COUNT(JobId) AS ' . $type . ' '; + $query .= 'FROM Job '; + $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' "; + $query .= $where; + + $jobs = $this->db_link->query( $query ); + + if (PEAR::isError( $jobs ) ) { + die( "Unable to get last $type jobs status from catalog
" . $status->getMessage() ); + }else { + $res = $jobs->fetchRow(); + return array( $label , current($res) ); + } + } // end function GetJobsStatistics() + + public function GetPoolsStatistics() + { + } } // end class Bweb ?> diff --git a/gui/bacula-web/graph.png b/gui/bacula-web/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..8c2fe8f094c795d194f033c4c731a751a0317cd4 GIT binary patch literal 2229 zcmV;m2uk;fP)Z9j(F~+T zlWvB=@)R-wK0Jj?Aydd_`?F@-=mip7y#&EZT}Q4r5u zd8O+P5I*;MjO_1+J6(5xjO;VrBZv6GJh2T{5CjEsZ2J?-XyrisC#*x3G0TBOaM-4< zVj$tcVkE}#LY8*QbM`jblH%hL`GUj*i^@2vKL}QT76PGk#1|xz!yK*<5NZlR119tf z`kc^vgfZX#?GgDp5*I8+k^^KjWfN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_9u8RXPh zT|k1DzZ_&`+doqy#FH-w1V@7)M`M)?!sg#STuQW{5=j7I9G1o^8wd}V0slZ?&Xj9K~^(KRuH9U&jg}RTefhef$Y~sIbFPhPs-HqdlNDx(5oEWd zSh8|~$QG+yvVyW@29e<^m#iR5EFe5wB@GFn&-OJ?_{RS&`}DVeO0Y*|6JdM}%- z086YOTe!*^5@3lPll~1@}keY%;-{;iwCp025t zTydE_nOeye7a}H<9mMdv5!J~Quc@6_Nx`N}P1(T(nnLGa(vTfoP1xcpQy00000NkvXXu0mjf D?>GCW literal 0 HcmV?d00001 diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 84c36b73c1..55c6f88ff8 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -187,14 +187,19 @@ else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){ */ } -// A simple graphing test with the new PHP BGraph classe -$data = array( array( 'Completed', 15 ), array( 'Failed', 2 ) ); +// Create a graph for last 24 hours job status +$data = array(); +$status = array( 'completed', 'completed_errors', 'failed', 'waiting', 'created', 'running', 'error' ); -$graph = new BGraph( "toto.png" ); +foreach( $status as $job_status ) { + array_push( $data, $dbSql->GetJobsStatistics( $job_status ) ); +} + +$graph = new BGraph( ); $graph->SetData( $data, 'pie', 'text-data-single' ); -$graph->SetTitle("Overall jobs status"); -$graph->SetGraphSize( 350, 200 ); -$graph->SetColors( array('green', 'red') ); +//$graph->SetTitle("Overall jobs status"); +$graph->SetGraphSize( 400, 230 ); +//$graph->SetColors( array('green', 'yellow','red','blue','white','green','red') ); $graph->Render(); $smarty->assign('graph', $graph->Get_Image_file() ); diff --git a/gui/bacula-web/templates/index.tpl b/gui/bacula-web/templates/index.tpl index bc9a8a7907..03031cecd7 100644 --- a/gui/bacula-web/templates/index.tpl +++ b/gui/bacula-web/templates/index.tpl @@ -21,7 +21,19 @@ {include file=volumes.tpl} + +{if $server==""} + +{else} + +{/if} +
+ +
+

Job Status Report (last 24 hours)

+ +

General informations

@@ -42,16 +54,6 @@
{include file="$last_report"} - -
-

General report

- {if $server==""} - - {else} - - {/if} - -
-- 2.39.5