From 011bb5ed1315e952a6ade87c309469418a7cb5be Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Mon, 29 Nov 2010 18:10:06 +0100 Subject: [PATCH] bacula-web: Improved Elapsed time function - 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 | 40 +++++++++++++++++++- gui/bacula-web/index.php | 29 ++++---------- gui/bacula-web/templates/last_run_report.tpl | 2 +- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/gui/bacula-web/classes.inc.php b/gui/bacula-web/classes.inc.php index ec853ecabd..b04188141f 100644 --- a/gui/bacula-web/classes.inc.php +++ b/gui/bacula-web/classes.inc.php @@ -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
" . $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
query = $query
" . $result->getMessage() ); + }else { + while( $time = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { + //echo 'elapsed = ' . $time['elapsed'] . '
'; + $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 { diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 538f62b753..f2a5cc171c 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -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.