]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved Elapsed time function
authorDavide Franco <bacula-dev@dflc.ch>
Mon, 29 Nov 2010 17:10:06 +0000 (18:10 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:39:41 +0000 (14:39 +0200)
 - New function Get_ElapsedTime_Job in Bweb classe
 - Changed elapsed time in index.php and last_run_report.tpl

gui/bacula-web/classes.inc.php
gui/bacula-web/index.php
gui/bacula-web/templates/last_run_report.tpl

index ec853ecabd6659022e76682466f452009858aaae..b04188141f4b2d5656a2f8df4c0e183b3da55f3b 100644 (file)
@@ -379,7 +379,7 @@ class Bweb extends DB {
                
                        $jobs = $this->db_link->query( $query );
                
-                       if (PEAR::isError( $lastjobstatus ) ) {
+                       if (PEAR::isError( $jobs ) ) {
                                die( "Unable to get last completed jobs status from catalog<br />" . $status->getMessage() );
                        }else {
                                return $jobs->fetchRow();
@@ -437,6 +437,44 @@ class Bweb extends DB {
                        }
                }
                
+               public function Get_ElapsedTime_Job( $delay = LAST_DAY )
+               {
+                       $query                  = "";
+                       $total_elapsed  = 0;
+                       
+                       // 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 );
+                       
+                       switch( $this->driver )
+                       {
+                               case 'mysql':
+                                       $query  = "SELECT UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime) AS elapsed from Job ";
+                                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
+                               break;
+                       }
+                       $result = $this->db_link->query( $query );
+                       
+                       if( PEAR::isError($result) ){
+                               die( "Unable to get elapsed time for jobs from catalog<br />query = $query <br />" . $result->getMessage() );
+                       }else {
+                               while( $time = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
+                                       //echo 'elapsed = ' . $time['elapsed'] . '<br />';
+                                       $total_elapsed += $time['elapsed'];
+                               }
+                               // Verify if elapsed time is more than 1 day
+                               if ( $total_elapsed > 86400 ) {
+                                       return gmstrftime("%d days %H:%M:%S", $total_elapsed );
+                               }else {
+                                       return gmstrftime("%H:%M:%S", $total_elapsed );
+                               }
+                       }
+               }
+                       
+               
 } // end class Bweb
 
 class BGraph {
index 538f62b75300f909dc9fca8211eabf5b25103538..f2a5cc171c588dc89290c0e8d898837260a7eb12 100644 (file)
@@ -121,40 +121,23 @@ $smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
 $nb_clients = $dbSql->Get_Nb_Clients();
 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
 
-/*if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
-        if ( $dbSql->driver == "mysql" )
-          $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
-        if ( $dbSql->driver == "pgsql")
-          $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800 * interval '1 second'" )
-            or die ("Error query: 4.1");
-        $smarty->assign('when',"yesterday");
-        $tmp = $last24bytes->fetchRow();        
-}*/
-
 // Backup Job list for report.tpl and last_run_report.tpl
 $smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
 
-/*$res = $dbSql->db_link->query("select Name from Job group by Name");
-
-$a_jobs = array();
-while( $tmp = $res->fetchRow() )
-        array_push($a_jobs, $tmp[0]);
-$smarty->assign('total_name_jobs',$a_jobs);
-$smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
-$res->free();
-*/
-
 // Get volumes list (volumes.tpl)
 $smarty->assign('pools',$dbSql->GetVolumeList() );
 
-// Completed jobs number
+// Last 24 hours completed jobs number (last_run_report.tpl)
 $failed_jobs = $dbSql->GetLastJobs();
 $smarty->assign( 'completed_jobs', $failed_jobs['completed_jobs'] );
 
-// Failed jobs number (last_run_report.tpl)
+// Last 24 hours failed jobs number (last_run_report.tpl)
 $failed_jobs = $dbSql->GetLastErrorJobs();
 $smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
 
+// Last 24 hours elapsed time (last_run_report.tpl)
+$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
+
 // last_run_report.tpl
 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
         // Total Elapsed Time. Only for single Job.
@@ -174,6 +157,8 @@ if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
         $smarty->assign('TotalElapsed',$TotalElapsed);
         $ret->free();
+               
+               
 }
 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
         $tmp1 = array();
index 0797434b466f5e32cda8f53f844455f26fb2573b..23fa288e5704bf08185ecff02d09213e58fd2159 100644 (file)
@@ -11,7 +11,7 @@
        <td class="label">Completed jobs</td> <td class="info">{$completed_jobs}</td>
  </tr> 
  <tr>
-       <td class="label">Elapsed time</td> <td class="info">{$totalElapsed}</td>
+       <td class="label">Elapsed time</td> <td class="info">{$elapsed_jobs}</td>
  </tr>
  <tr>
        <td class="label">Transferred Bytes</td> <td class="info">{$bytes_totales}</td>