Ejemplo n.º 1
0
                 $sHigh[] = array("name" => $sServer->sName);
             }
             $sBandwidthDifference = "{$sBandwidthDifference} Mbps";
         }
     }
     // Calculates Free IP Space
     if ($sBlockList = $database->CachedQuery("SELECT * FROM `server_blocks` WHERE `server_id` = :ServerId", array("ServerId" => $sServer->sId))) {
         foreach ($sBlockList->data as $sBlockRow) {
             if ($sIPList = $database->CachedQuery("SELECT * FROM `ipaddresses` WHERE `block_id` = :BlockId AND `vps_id` = :VPSId", array("BlockId" => $sBlockRow["block_id"], "VPSId" => 0))) {
                 $sIPCount = $sIPCount + count($sIPList->data);
             }
         }
     } else {
         $sIPCount = "0";
     }
     $sStatistics[] = array("name" => $sServer->sName, "load_average" => $sServer->sLoadAverage, "disk_usage" => $sHardDiskUsed, "disk_free" => $sHardDiskFree, "ram_usage" => $sRAMUsed, "ram_free" => $sRAMFree, "status" => $sServer->sStatus, "uptime" => ConvertTime(round($sServer->sHardwareUptime, 0)), "ip_count" => $sIPCount, "type" => $sType, "bandwidth" => $sBandwidthDifference);
     if (empty($sServer->sStatus)) {
         $sDown[] = array("name" => $sServer->sName);
     }
     // Cleanup just in case.
     unset($sHardDiskUsed);
     unset($sHardDiskFree);
     unset($sRAMUsed);
     unset($sRAMFree);
     unset($sLastCheck);
     unset($sPreviousCheck);
     unset($sBandwidth);
     unset($sLastBandwidth);
     unset($sBandwidthDifference);
     unset($sIPCount);
 }
Ejemplo n.º 2
0
 public function openvz_statistics($sUser, $sVPS, $sRequested)
 {
     global $sTemplate;
     global $database;
     global $locale;
     $sServer = new Server($sVPS->sServerId);
     $sSSH = Server::server_connect($sServer);
     $sLog[] = array("command" => "vzctl status {$sVPS->sContainerId}", "result" => $sSSH->exec("vzctl status {$sVPS->sContainerId}"));
     if (strpos($sLog[0]["result"], 'running') === false) {
         return $sArray = array("json" => 1, "type" => "status", "result" => "offline", "hostname" => $sVPS->sHostname);
     } else {
         $sUptime = explode(' ', $sSSH->exec("vzctl exec {$sVPS->sContainerId} cat /proc/uptime"));
         $sRAM = explode('kB', $sSSH->exec("vzctl exec {$sVPS->sContainerId} cat /proc/meminfo"));
         $sUsedRAM = preg_replace("/[^0-9]/", "", $sRAM[0]) - preg_replace("/[^0-9]/", "", $sRAM[1]);
         $sTotalRAM = preg_replace("/[^0-9]/", "", $sRAM[0]);
         $sUsedSWAP = preg_replace("/[^0-9]/", "", $sRAM[11]) - preg_replace("/[^0-9]/", "", $sRAM[12]);
         if ($sUsedSWAP < 0) {
             $sUsedSWAP = preg_replace("/[^0-9]/", "", $sRAM[12]) - preg_replace("/[^0-9]/", "", $sRAM[13]);
         }
         $sTotalSWAP = $sVPS->sSWAP;
         $sDisk = $sSSH->exec("vzctl exec {$sVPS->sContainerId} df");
         $sDisk = explode("\n", trim($sDisk));
         array_shift($sDisk);
         foreach ($sDisk as $sValue) {
             $sValue = explode(" ", preg_replace("/\\s+/", " ", $sValue));
             if (is_numeric($sValue[2])) {
                 $sDiskUsed = $sDiskUsed + $sValue[2];
             }
         }
         $sDiskUsed = $sDiskUsed / 1048576;
         $sDiskTotal = $sVPS->sDisk;
         $sCPU = explode(' ', $sSSH->exec("vzctl exec {$sVPS->sContainerId} cat /proc/loadavg"));
         if ($sUsedRAM > 0) {
             $sUsedRAM = round($sUsedRAM / 1024, 0);
         }
         if ($sTotalRAM > 0) {
             $sTotalRAM = round($sTotalRAM / 1024, 0);
         }
         if ($sUsedRAM > 0 && $sTotalRAM > 0) {
             $sPercentRAM = round(100 / $sTotalRAM * $sUsedRAM, 0);
         } else {
             $sPercentRAM = 0;
         }
         if ($sUsedSWAP > 0) {
             $sUsedSWAP = round($sUsedSWAP / 1024, 0);
         }
         if ($sUsedSWAP > 0 && $sTotalSWAP > 0) {
             $sPercentSWAP = round(100 / $sTotalSWAP * $sUsedSWAP, 0);
         } else {
             $sPercentSWAP = 0;
         }
         if ($sDiskUsed > 0 && $sDiskTotal > 0) {
             $sPercentDisk = round(100 / $sDiskTotal * $sDiskUsed, 0);
         } else {
             $sPercentDisk = 0;
         }
         if ($sCPU[0] > 0 && $sVPS->sCPULimit > 0) {
             $sPercentCPU = round(100 / $sVPS->sCPULimit * ($sCPU[0] * 100), 0);
         } else {
             $sPercentCPU = 0;
         }
         if ($sVPS->sCPULimit > 0) {
             $sCores = round($sVPS->sCPULimit / 100, 0);
         } else {
             $sCores = 0;
         }
         if ($sDiskUsed < 1) {
             $sDiskUsed = round($sDiskUsed, 2);
         } else {
             $sDiskUsed = round($sDiskUsed, 0);
         }
         if ($sTemplates = $database->CachedQuery("SELECT * FROM templates WHERE `id` = :TemplateId", array('TemplateId' => $sVPS->sTemplateId))) {
             $sVPSTemplate = new Template($sVPS->sTemplateId);
             $sTemplateName = $sVPSTemplate->sName;
         } else {
             $sTemplateName = "N/A";
         }
         if ($sVPS->sBandwidthUsage > 0) {
             $sBandwidthUsage = FormatBytes($sVPS->sBandwidthUsage, 2);
         } else {
             $sBandwidthUsage = "0 MB";
         }
         if (!empty($sVPS->sBandwidthLimit) && !empty($sVPS->sBandwidthUsage)) {
             $sPercentBandwidth = round(100 / ($sVPS->sBandwidthLimit * 1024) * $sVPS->sBandwidthUsage, 0);
             if (empty($sPercentBandwidth)) {
                 $sPercentBandwidth = 0;
             }
         } else {
             $sPercentBandwidth = 0;
         }
         $sStatistics = array("info" => array("uptime" => ConvertTime($sUptime[0]), "used_ram" => $sUsedRAM, "total_ram" => $sTotalRAM, "percent_ram" => $sPercentRAM, "used_swap" => $sUsedSWAP, "total_swap" => $sTotalSWAP, "percent_swap" => $sPercentSWAP, "used_disk" => $sDiskUsed, "total_disk" => round($sDiskTotal, 0), "percent_disk" => $sPercentDisk, "total_cpu" => $sVPS->sCPULimit, "total_cores" => $sCores, "used_cores" => $sCPU[0], "used_cpu" => $sCPU[0] * 100, "percent_cpu" => $sPercentCPU, "load_average" => "{$sCPU['0']} {$sCPU['1']} {$sCPU['2']}", "bandwidth_usage" => $sBandwidthUsage, "bandwidth_limit" => FormatBytes($sVPS->sBandwidthLimit * 1024, 0), "percent_bandwidth" => round(100 / ($sVPS->sBandwidthLimit * 1024) * $sVPS->sBandwidthUsage, 0), "operating_system" => $sTemplateName, "hostname" => $sVPS->sHostname, "primary_ip" => $sVPS->sPrimaryIP));
         $sStatistics = Templater::AdvancedParse($sTemplate->sValue . '/' . $sVPS->sType . '.statistics', $locale->strings, array("Statistics" => $sStatistics));
         return $sArray = array("json" => 1, "type" => "status", "result" => "online", "content" => $sStatistics, "hostname" => $sVPS->sHostname);
     }
 }