From: Davide Franco Date: Thu, 2 Dec 2010 13:23:19 +0000 (+0100) Subject: bacula-web: Improved bgraph classe and new status job graph in dashboard X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fda2ac939949ec8f3b3209552e40b9ad54a46b6f;p=bacula%2Fbacula 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 --- 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 0000000000..8c2fe8f094 Binary files /dev/null and b/gui/bacula-web/graph.png differ 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} - -