public static function get_Size($pdo_connection, $catalog_id) { $db_name = FileConfig::get_Value('db_name', $catalog_id); switch (CDB::getDriverName()) { case 'mysql': // Return N/A for MySQL server prior version 5 (no information_schemas) if (version_compare(CDB::getServerVersion(), '5.0.0') >= 0) { // Prepare SQL statment $statment = array('table' => 'information_schema.TABLES', 'fields' => array("table_schema AS 'database', (sum( data_length + index_length) / 1024 / 1024 ) AS 'dbsize'"), 'where' => array("table_schema = '{$db_name}'"), 'groupby' => 'table_schema'); $result = CDBUtils::runQuery(CDBQuery::get_Select($statment, $pdo_connection), $pdo_connection); $db_size = $result->fetch(); $db_size = $db_size['dbsize'] * 1024 * 1024; return CUtils::Get_Human_Size($db_size); } else { echo 'Not supported (' . CDB::getServerVersion() . ') <br />'; } break; case 'pgsql': $statment = "SELECT pg_database_size('{$db_name}') AS dbsize"; $result = CDBUtils::runQuery($statment, $pdo_connection); $db_size = $result->fetch(); return CUtils::Get_Human_Size($db_size['dbsize']); break; case 'sqlite': $db_size = filesize(FileConfig::get_Value('db_name', $catalog_id)); return CUtils::Get_Human_Size($db_size); break; } }
$job['compression'] = number_format($compression, 2); } else { $job['compression'] = 'N/A'; } // Job speed $start = $job['starttime']; $end = $job['endtime']; $seconds = DateTimeUtil::get_ElaspedSeconds($end, $start); if ($seconds !== false && $seconds > 0) { $speed = $job['jobbytes'] / $seconds; $job['speed'] = CUtils::Get_Human_Size($speed, 2) . '/s'; } else { $job['speed'] = 'N/A'; } // Job bytes more easy to read $job['jobbytes'] = CUtils::Get_Human_Size($job['jobbytes']); $job['jobfiles'] = CUtils::format_Number($job['jobfiles']); $jobs[] = $job; } // end while } catch (Exception $e) { CErrorHandler::displayError($e); } $view->assign('jobs', $jobs); $view->assign('backupjob_name', $backupjob_name); $view->assign('backupjob_period', $backupjob_period); $view->assign('backupjob_bytes', $backupjob_bytes); $view->assign('backupjob_files', $backupjob_files); // Set page name $current_page = 'Backup job report'; $view->assign('page_name', $current_page);
public function UniformizeData($data_in) { $array_sum = 0; $best_unit = ''; // Uniformize data array element based on best unit foreach ($data_in as $key => $data) { if (is_null($data[1])) { $data_in[$key][1] = 0; } } // Calculate sum of all values foreach ($data_in as $value) { $array_sum += $value[1]; } // Calculate average value and best unit $avg = $array_sum / count($data_in); list($value, $best_unit) = explode(' ', CUtils::Get_Human_Size($avg, 1)); foreach ($data_in as $key => $value) { $data_in[$key][1] = CUtils::Get_Human_Size($value[1], 1, $best_unit, false); } $this->plot->SetYTitle($best_unit); return $data_in; }
$view->assign('database_size', Database_Model::get_Size($dbSql->db_link, $dbSql->catalog_current_id)); // Total bytes and files stored over the last 24 hours $view->assign('bytes_last', CUtils::Get_Human_Size(Jobs_Model::getStoredBytes($dbSql->db_link, $custom_period))); $view->assign('files_last', CUtils::format_Number(Jobs_Model::getStoredFiles($dbSql->db_link, $custom_period))); // Number of clients $view->assign('clients', Clients_Model::count($dbSql->db_link)); // Defined Jobs and Filesets $view->assign('defined_filesets', FileSets_Model::count($dbSql->db_link)); $view->assign('defined_jobs', Jobs_Model::count_Job_Names($dbSql->db_link)); // Incremental, Differential and Full jobs over the last 24 hours $view->assign('incr_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_INCR)); $view->assign('diff_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_DIFF)); $view->assign('full_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_FULL)); // Volumes disk usage $volumes_size = Volumes_Model::getDiskUsage($dbSql->db_link); $view->assign('volumes_size', CUtils::Get_Human_Size($volumes_size)); // Pools count $view->assign('pools_nb', Pools_Model::count($dbSql->db_link)); // Backup Job list $view->assign('jobs_list', Jobs_Model::get_Jobs_List($dbSql->db_link)); // Clients list $view->assign('clients_list', Clients_Model::getClients($dbSql->db_link)); // Count volumes $view->assign('volumes_nb', Volumes_Model::count($dbSql->db_link)); // ============================================================== // Last period <Job status graph> // ============================================================== $jobs_status = array('Running', 'Completed', 'Waiting', 'Failed', 'Canceled'); $jobs_status_data = array(); foreach ($jobs_status as $status) { $jobs_count = Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, strtolower($status));
if ($job['jobbytes'] > 0) { $compression = 1 - $job['jobbytes'] / $job['readbytes']; $job['compression'] = number_format($compression, 2); } else { $job['compression'] = 'N/A'; } // Job bytes more easy to read $job['jobbytes'] = CUtils::Get_Human_Size($job['jobbytes']); $job['jobfiles'] = CUtils::format_Number($job['jobfiles']); // Job speed $start = new DateTime($job['starttime']); $end = new DateTime($job['endtime']); $seconds = $end->getTimeStamp() - $start->getTimeStamp(); if ($seconds > 0) { $speed = $job['jobbytes'] / $seconds; $job['speed'] = CUtils::Get_Human_Size($speed, 1) . '/s'; } else { $job['speed'] = 'N/A'; } $jobs[] = $job; } // end while } catch (Exception $e) { CErrorHandler::displayError($e); } $view->assign('jobs', $jobs); $view->assign('backupjob_name', $backupjob_name); $view->assign('backupjob_period', $backupjob_period); $view->assign('backupjob_bytes', $backupjob_bytes); $view->assign('backupjob_files', $backupjob_files); // Set page name
public function GetVolumeList() { $volumes = ''; $volumes_list = array(); $query = ""; //MKO Aggiunto per calcolo TTL $time = time(); $dtF = new DateTime("@0"); //END MKO foreach (Pools_Model::getPools($this->db_link) as $pool) { switch ($this->db_driver) { case 'sqlite': case 'mysql': //MKO Aggiunto per firstwritten per calcolo TTL $query = "SELECT Media.voluseduration, Media.inchanger, Media.slot, Media.firstwritten, Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename"; break; case 'pgsql': $query = "SELECT media.voluseduration, media.inchanger, media.slot, media.firstwritten, media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename"; //END MKO break; } // end switch $volumes = CDBUtils::runQuery($query, $this->db_link); if (!array_key_exists($pool['name'], $volumes_list)) { $volumes_list[$pool['name']] = array(); } foreach ($volumes->fetchAll() as $volume) { if ($volume['lastwritten'] != "0000-00-00 00:00:00") { // Calculate expiration date if the volume is Full if ($volume['volstatus'] == 'Full') { $expire_date = strtotime($volume['lastwritten']) + $volume['volretention']; $volume['expire'] = strftime("%Y-%m-%d", $expire_date); } else { $volume['expire'] = 'N/A'; } //MKO Calcolo Append Life $timediff = $time - strtotime($volume['firstwritten']); if ($volume['volstatus'] == 'Append') { $remaining = $volume['voluseduration'] - $timediff; if ($remaining < 0) { $remaining = 0; } $dtT = new DateTime("@{$remaining}"); $volume['volstatus'] = $volume['volstatus'] . ' (' . $dtF->diff($dtT)->format('%ad %Hh %im %ss') . ')'; } //MKO Calcolo TTL $ttl = $volume['volretention'] - $timediff; $dtT = new DateTime("@{$ttl}"); $ttl > 0 ? $volume['ttl'] = $dtF->diff($dtT)->format('%ad %Hh %im %ss') : ($volume['ttl'] = 'Expired'); //MKO In Changer $volume['inchanger'] ? $volume['changer'] = 'Slot: ' . $volume['slot'] : ($volume['changer'] = 'No'); // Media used bytes in a human format $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']); } else { $volume['lastwritten'] = "N/A"; $volume['expire'] = "N/A"; $volume['volbytes'] = "0 KB"; } $volume['volretention'] = $volume['volretention'] / 60 / 60 / 24 . 'd'; // Add the media in pool array array_push($volumes_list[$pool['name']], $volume); } // end foreach volumes } // end foreach pools return $volumes_list; }
public function GetVolumeList() { $pools = array(); $query = ""; foreach (Pools_Model::getPools($this->db_link) as $pool) { $pool_name = $pool['name']; switch ($this->db_driver) { case 'sqlite': case 'mysql': $query = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention, Media.slot\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename"; break; case 'pgsql': $query = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention, media.slot\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename"; break; } // end switch $volumes = CDBUtils::runQuery($query, $this->db_link); // If we have at least 1 volume in this pool, create sub array for the pool if (!array_key_exists($pool_name, $pools)) { $pools[$pool_name] = array(); $pools[$pool_name]['volumes'] = array(); } foreach ($volumes->fetchAll() as $volume) { // Set volume default values $volume['expire'] = 'n/a'; // Set value for unused volumes if (empty($volume['lastwritten'])) { $volume['lastwritten'] = 'n/a'; } // Media used bytes in a human format $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']); // If volume have alreday been used if ($volume['lastwritten'] != "0000-00-00 00:00:00") { // Calculate expiration date only if the volume is Full if ($volume['volstatus'] == 'Full') { $expire_date = strtotime($volume['lastwritten']) + $volume['volretention']; $volume['expire'] = strftime("%Y-%m-%d", $expire_date); } } // Push the volume array to the $pool array array_push($pools[$pool_name]['volumes'], $volume); } // end foreach volumes // Calulate used bytes for each pool $sql = "SELECT SUM(Media.volbytes) FROM Media WHERE Media.PoolId = '" . $pool['poolid'] . "'"; $result = CDBUtils::runQuery($sql, $this->db_link); $result = $result->fetchAll(); $pools[$pool_name]['total_used_bytes'] = CUtils::Get_Human_Size($result[0]['sum']); } // end foreach pools return $pools; }