]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved bgraph classe and new status job graph in dashboard
authorDavide Franco <bacula-dev@dflc.ch>
Thu, 2 Dec 2010 13:23:19 +0000 (14:23 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:39:43 +0000 (14:39 +0200)
 - 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
gui/bacula-web/bweb.inc.php
gui/bacula-web/graph.png [new file with mode: 0644]
gui/bacula-web/index.php
gui/bacula-web/templates/index.tpl

index 9ea23f3b3dd242f42d8adf63ed32c4dc8cf72300..9f0fb218a3d27f5f70f367d16e6f2ad2ef7c4b9c 100644 (file)
@@ -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 );
                
index 60f9be11a494d3030d0fbb03ad7a1fa5dc667a55..a201188c9b3ea1996ca5a551fc9b1e7db1ffd80e 100644 (file)
@@ -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<br />" . $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 (file)
index 0000000..8c2fe8f
Binary files /dev/null and b/gui/bacula-web/graph.png differ
index 84c36b73c1397d8a28d6a85b1f026d1d6e5105d0..55c6f88ff88d3f72abe55e5cbf36f7d550e3dc11 100644 (file)
@@ -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() );
index bc9a8a790778d6f4630c3f3899650bd9fcfa6f75..03031cecd746a5c164512873b40cfde3ccd2dc3c 100644 (file)
 {include file=volumes.tpl}
 </div>
 
+<!-- To be removed -->
+{if $server==""} 
+  <!-- <img class="report" src="stats.php?server={$server}&amp;tipo_dato=69&amp;title=General%20report&amp;modo_graph=bars&amp;sizex=420&amp;sizey=250&amp;MBottom=20&amp;legend=1" alt="" /> -->
+{else}
+  <!-- <img class="report" src="stats.php?server={$server}&amp;tipo_dato=3&amp;title={$server}&amp;modo_graph=bars" alt="" /> -->
+{/if} 
+
 <div id="main_right">
+  <!-- Last job Status -->
+  <div class="box">
+       <p class="title">Job Status Report (last 24 hours)</p>
+         <img src="{$graph}" alt="" /> 
+  </div> <!-- end div box -->
   <!-- General information -->
   <div class="box">
        <p class="title">General informations</p>
   </div>
        
   {include file="$last_report"}        
-  
-  <div class="box">
-       <p class="title">General report</p>
-       {if $server==""} 
-         <!-- <img class="report" src="stats.php?server={$server}&amp;tipo_dato=69&amp;title=General%20report&amp;modo_graph=bars&amp;sizex=420&amp;sizey=250&amp;MBottom=20&amp;legend=1" alt="" /> -->
-       {else}
-         <!-- <img class="report" src="stats.php?server={$server}&amp;tipo_dato=3&amp;title={$server}&amp;modo_graph=bars" alt="" /> -->
-       {/if} 
-         <img src="{$graph}" alt="" /> 
-  </div> <!-- end div box -->
 
 </div> <!-- end div main_right -->