示例#1
0
 function statistics()
 {
     $resources_all = 0;
     $resources_active = 0;
     $resources_available = 0;
     $dc_load_overall = 0;
     $appliance_load_overall = 0;
     $appliance_active = 0;
     $storage_load_overall = 0;
     $storage_active = 0;
     $cpu_total = 0;
     $mem_used = 0;
     $mem_total = 0;
     // run only each minute
     $db = openqrm_get_db_connection();
     $rs = $db->Execute("select MAX(datacenter_id) from {$this->_db_table}");
     foreach ($rs as $index => $dc) {
         if (isset($dc['MAX(datacenter_id)'])) {
             $this->last_statistics = $dc['MAX(datacenter_id)'];
         } else {
             if (isset($dc['max'])) {
                 $this->last_statistics = $dc['max'];
             }
         }
     }
     // get an array of resources which are assigned to an appliance
     $appliance_resources_array = array();
     $appliance = new appliance();
     $appliance_list = $appliance->get_all_ids();
     foreach ($appliance_list as $app) {
         $app_id = $app['appliance_id'];
         $g_appliance = new appliance();
         $g_appliance->get_instance_by_id($app_id);
         $g_appliance_resource = $g_appliance->resources;
         if (!strcmp($g_appliance->state, "active") || $g_appliance_resource == 0) {
             if ($g_appliance_resource != "-1") {
                 $appliance_resources_array[] .= $g_appliance_resource;
             }
         }
     }
     // get an array of resources which are a storage server
     $storage_resources_array = array();
     $storage = new storage();
     $storage_list = $storage->get_list();
     foreach ($storage_list as $store) {
         $storage_id = $store['value'];
         $g_storage = new storage();
         $g_storage->get_instance_by_id($storage_id);
         $g_storage_resource = $g_storage->resource_id;
         $storage_resources_array[] .= $g_storage_resource;
     }
     $resource = new resource();
     $resource_list = $resource->get_list();
     foreach ($resource_list as $res) {
         $res_id = $res['resource_id'];
         //echo "!! res_id $res_id <br>";
         $g_resource = new resource();
         $g_resource->get_instance_by_id($res_id);
         // start gathering
         $resources_all++;
         $cpu_total = $cpu_total + $g_resource->cpunumber;
         $mem_used = $mem_used + $g_resource->memused;
         $mem_total = $mem_total + $g_resource->memtotal;
         // resource load
         if ("{$g_resource->imageid}" == "1" && "{$g_resource->state}" == "active") {
             // idle
             $resources_available++;
         } else {
             if ("{$g_resource->state}" == "active") {
                 // active
                 $resources_active++;
                 $dc_load_overall = $dc_load_overall + $g_resource->load;
                 // is storage ?
                 if (in_array($g_resource->id, $storage_resources_array)) {
                     $storage_active++;
                     $storage_load_overall = $storage_load_overall + $g_resource->load;
                 }
                 // is appliance ?
                 if (in_array($g_resource->id, $appliance_resources_array)) {
                     $appliance_active++;
                     $appliance_load_overall = $appliance_load_overall + $g_resource->load;
                 }
             }
         }
     }
     if ($resources_active != 0) {
         $dc_load_overall = $dc_load_overall / $resources_active;
         $dc_load_overall = number_format($dc_load_overall, 2, '.', '');
     }
     if ($appliance_active != 0) {
         $appliance_load_overall = $appliance_load_overall / $appliance_active;
         $appliance_load_overall = number_format($appliance_load_overall, 2, '.', '');
     }
     if ($storage_active != 0) {
         $storage_load_overall = $storage_load_overall / $storage_active;
         $storage_load_overall = number_format($storage_load_overall, 2, '.', '');
     }
     $datacenter_fields = array();
     $datacenter_fields['datacenter_load_overall'] = $dc_load_overall;
     $datacenter_fields['datacenter_load_server'] = $appliance_load_overall;
     $datacenter_fields['datacenter_load_storage'] = $storage_load_overall;
     $datacenter_fields['datacenter_cpu_total'] = $cpu_total;
     $datacenter_fields['datacenter_mem_total'] = $mem_total;
     $datacenter_fields['datacenter_mem_used'] = $mem_used;
     $stats_count = $this->get_count();
     if ($stats_count >= $this->resolution) {
         $rs = $db->Execute("select MIN(datacenter_id) from {$this->_db_table}");
         foreach ($rs as $index => $dc) {
             if (isset($dc['MIN(datacenter_id)'])) {
                 $this->oldest_statistics_id = $dc['MIN(datacenter_id)'];
             } else {
                 if (isset($dc['min'])) {
                     $this->oldest_statistics_id = $dc['min'];
                 }
             }
         }
         $rs = $db->Execute("delete from {$this->_db_table} where datacenter_id={$this->oldest_statistics_id}");
         $stats_count = $this->get_count();
     }
     $datacenter_fields['datacenter_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
     $result = $db->AutoExecute($this->_db_table, $datacenter_fields, 'INSERT');
     if (!$result) {
         $this->event->log("add", $_SERVER['REQUEST_TIME'], 2, "datacenter.class.php", "Failed updating datacenter " . $datacenter_fields['datacenter_id'], "", "", 0, 0, 0);
     }
 }
示例#2
0
 $arHead['storage_icon'] = array();
 $arHead['storage_icon']['title'] = '';
 $arHead['storage_id'] = array();
 $arHead['storage_id']['title'] = 'ID';
 $arHead['storage_name'] = array();
 $arHead['storage_name']['title'] = 'Name';
 $arHead['storage_resource'] = array();
 $arHead['storage_resource']['title'] = 'Res.';
 $arHead['storage_type'] = array();
 $arHead['storage_type']['title'] = 'Type';
 $arHead['storage_load'] = array();
 $arHead['storage_load']['title'] = 'Load';
 $arBody = array();
 $store_load_array = array();
 $storage = new storage();
 $storage_list = $storage->get_list();
 foreach ($storage_list as $st) {
     $store_all++;
     $storage_id = $st['value'];
     $g_storage = new storage();
     $g_storage->get_instance_by_id($storage_id);
     // check resource state
     $st_resource = new resource();
     $st_resource->get_instance_by_id($g_storage->resource_id);
     if ("{$st_resource->state}" == "active") {
         $store_load = $st_resource->load;
         $store_load_array[$g_storage->id] = $st_resource->load;
     } else {
         if ("{$st_resource->state}" == "error") {
             $store_error++;
         }
示例#3
0
 function dc_status()
 {
     // number of idle systems
     $resources_all = 0;
     // active deployed resources
     $resources_active = 0;
     // resources in error state
     $resources_error = 0;
     // physical resources
     $resources_physical = 0;
     // virtual resources
     $resources_virtual = 0;
     // number of idle systems
     $resources_available = 0;
     // physical resource available
     $resources_available_physical = 0;
     // virtal resource available
     $resources_available_virtual = 0;
     // overall load
     $dc_load_overall = 0;
     // active appliance load
     $appliance_load_overall = 0;
     // peak in appliance load
     $appliance_load_peak = 0;
     // active appliances
     $appliance_active = 0;
     // active appliance with resource in error state
     $appliance_error = 0;
     // storage load
     $storage_load_overall = 0;
     // storage peak
     $storage_load_peak = 0;
     // active storages
     $storage_active = 0;
     // storage with resource in error state
     $storage_error = 0;
     // get an array of resources which are assigned to an appliance
     $appliance_resources_array = array();
     $appliance = new appliance();
     $appliance_list = $appliance->get_all_ids();
     foreach ($appliance_list as $app) {
         $app_id = $app['appliance_id'];
         $g_appliance = new appliance();
         $g_appliance->get_instance_by_id($app_id);
         $g_appliance_resource = $g_appliance->resources;
         if (!strcmp($g_appliance->state, "active") || $g_appliance_resource == 0) {
             if ($g_appliance_resource != "-1") {
                 $appliance_resources_array[] .= $g_appliance_resource;
             }
         }
     }
     // get an array of resources which are a storage server
     $storage_resources_array = array();
     $storage = new storage();
     $storage_list = $storage->get_list();
     foreach ($storage_list as $store) {
         $storage_id = $store['value'];
         $g_storage = new storage();
         $g_storage->get_instance_by_id($storage_id);
         $g_storage_resource = $g_storage->resource_id;
         $storage_resources_array[] .= $g_storage_resource;
     }
     $restype = 0;
     $resource = new resource();
     $resource_list = $resource->get_list();
     foreach ($resource_list as $res) {
         $res_id = $res['resource_id'];
         //echo "!! res_id $res_id <br>";
         $g_resource = new resource();
         $g_resource->get_instance_by_id($res_id);
         // start gathering
         $resources_all++;
         // physical or virtual ?
         if (strlen($g_resource->vtype) && $g_resource->vtype != "NULL") {
             $virtualization = new virtualization();
             $virtualization->get_instance_by_id($g_resource->vtype);
             if (strstr($virtualization->type, "-vm")) {
                 // virtual
                 $resources_virtual++;
                 $restype = 1;
             } else {
                 // physical
                 $resources_physical++;
                 $restype = 0;
             }
         } else {
             // we treat unknown system types as physical
             $resources_physical++;
             $restype = 0;
         }
         // resource load
         // is idle or active ?
         if ("{$g_resource->imageid}" == "1" && "{$g_resource->state}" == "active") {
             // idle
             $resources_available++;
             // virtual or physical ?
             if ($restype == 0) {
                 $resources_available_physical++;
             } else {
                 $resources_available_virtual++;
             }
         } else {
             if ("{$g_resource->state}" == "active") {
                 // active
                 $resources_active++;
                 $dc_load_overall = $dc_load_overall + $g_resource->load;
                 // is storage ?
                 if (in_array($g_resource->id, $storage_resources_array)) {
                     $storage_active++;
                     $storage_load_overall = $storage_load_overall + $g_resource->load;
                     // is peak ?
                     if ($g_resource->load > $storage_load_peak) {
                         $storage_load_peak = $g_resource->load;
                     }
                 }
                 // is appliance ?
                 if (in_array($g_resource->id, $appliance_resources_array)) {
                     $appliance_active++;
                     $appliance_load_overall = $appliance_load_overall + $g_resource->load;
                     // is peak ?
                     if ($g_resource->load > $appliance_load_peak) {
                         $appliance_load_peak = $g_resource->load;
                     }
                 }
             } else {
                 if ("{$g_resource->state}" == "error") {
                     // error
                     $resources_error++;
                     // is storage ?
                     if (in_array($g_resource->id, $storage_resources_array)) {
                         $storage_error++;
                     }
                     // is appliance ?
                     if (in_array($g_resource->id, $appliance_resources_array)) {
                         $appliance_error++;
                     }
                 }
             }
         }
     }
     // end of gathering
     // divide with number of active resources, appliances + storages
     if ($resources_active != 0) {
         $dc_load_overall = $dc_load_overall / $resources_active;
         $dc_load_overall = number_format($dc_load_overall, 2, '.', '');
     }
     if ($appliance_active != 0) {
         $appliance_load_overall = $appliance_load_overall / $appliance_active;
         $appliance_load_overall = number_format($appliance_load_overall, 2, '.', '');
     }
     if ($storage_active != 0) {
         $storage_load_overall = $storage_load_overall / $storage_active;
         $storage_load_overall = number_format($storage_load_overall, 2, '.', '');
     }
     echo "{$dc_load_overall},{$storage_load_overall},{$storage_load_peak},{$appliance_load_overall},{$appliance_load_peak},{$resources_all},{$resources_physical},{$resources_virtual},{$resources_available},{$resources_available_physical},{$resources_available_virtual},{$resources_error},{$appliance_error},{$storage_error}";
     exit(0);
 }