function obtener_info_de_sistema() { $muestracpu = array(); $muestracpu[0] = obtener_muestra_actividad_cpu(); $arrInfo = array('MemTotal' => 0, 'MemFree' => 0, 'MemBuffers' => 0, 'SwapTotal' => 0, 'SwapFree' => 0, 'Cached' => 0, 'CpuModel' => '(unknown)', 'CpuVendor' => '(unknown)', 'CpuMHz' => 0.0); $arrExec = array(); $arrParticiones = array(); $varExec = ""; if ($fh = fopen("/proc/meminfo", "r")) { while ($linea = fgets($fh, "4048")) { // Aqui parseo algunos parametros if (preg_match("/^MemTotal:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["MemTotal"] = trim($arrReg[1]); } if (preg_match("/^MemFree:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["MemFree"] = trim($arrReg[1]); } if (preg_match("/^Buffers:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["MemBuffers"] = trim($arrReg[1]); } if (preg_match("/^SwapTotal:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["SwapTotal"] = trim($arrReg[1]); } if (preg_match("/^SwapFree:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["SwapFree"] = trim($arrReg[1]); } if (preg_match("/^Cached:[[:space:]]+([[:digit:]]+) kB/", $linea, $arrReg)) { $arrInfo["Cached"] = trim($arrReg[1]); } } fclose($fh); } if ($fh = fopen("/proc/cpuinfo", "r")) { while ($linea = fgets($fh, "4048")) { // Aqui parseo algunos parametros if (preg_match("/^model name[[:space:]]+:[[:space:]]+(.*)\$/", $linea, $arrReg)) { $arrInfo["CpuModel"] = trim($arrReg[1]); } if (preg_match("/^Processor[[:space:]]+:[[:space:]]+(.*)\$/", $linea, $arrReg)) { $arrInfo["CpuModel"] = trim($arrReg[1]); } if (preg_match("/^vendor_id[[:space:]]+:[[:space:]]+(.*)\$/", $linea, $arrReg)) { $arrInfo["CpuVendor"] = trim($arrReg[1]); } if (preg_match("/^cpu MHz[[:space:]]+:[[:space:]]+(.*)\$/", $linea, $arrReg)) { $arrInfo["CpuMHz"] = trim($arrReg[1]); } } fclose($fh); } exec("/usr/bin/uptime", $arrExec, $varExec); if ($varExec == "0") { if (preg_match("/up[[:space:]]+([[:digit:]]+ days?,)?(([[:space:]]*[[:digit:]]{1,2}:[[:digit:]]{1,2}),?)?([[:space:]]*[[:digit:]]+ min)?/", $arrExec[0], $arrReg)) { if (!empty($arrReg[3]) and empty($arrReg[4])) { list($uptime_horas, $uptime_minutos) = explode(":", $arrReg[3]); $arrInfo["SysUptime"] = $arrReg[1] . " {$uptime_horas} hour(s), {$uptime_minutos} minute(s)"; } else { if (empty($arrReg[3]) and !empty($arrReg[4])) { // Esto lo dejo asi $arrInfo["SysUptime"] = $arrReg[1] . $arrReg[3] . $arrReg[4]; } else { $arrInfo["SysUptime"] = $arrReg[1] . $arrReg[3] . $arrReg[4]; } } } } // Infomacion de particiones //- TODO: Aun no se soportan lineas quebradas como la siguiente: //- /respaldos/INSTALADORES/fedora-1/disco1.iso //- 644864 644864 0 100% /mnt/fc1/disc1 exec("/bin/df -P /etc/fstab", $arrExec, $varExec); if ($varExec == "0") { foreach ($arrExec as $lineaParticion) { if (preg_match("/^([\\/-_\\.[:alnum:]|-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)" . "[[:space:]]+([[:digit:]]{1,3}%)[[:space:]]+([\\/-_\\.[:alnum:]]+)\$/", $lineaParticion, $arrReg)) { $arrTmp = ""; $arrTmp["fichero"] = $arrReg[1]; $arrTmp["num_bloques_total"] = $arrReg[2]; $arrTmp["num_bloques_usados"] = $arrReg[3]; $arrTmp["num_bloques_disponibles"] = $arrReg[4]; $arrTmp["uso_porcentaje"] = $arrReg[5]; $arrTmp["punto_montaje"] = $arrReg[6]; $arrInfo["particiones"][] = $arrTmp; } } } usleep(250000); $muestracpu[1] = obtener_muestra_actividad_cpu(); $arrInfo['CpuUsage'] = calcular_carga_cpu_intervalo($muestracpu[0], $muestracpu[1]); return $arrInfo; }
function getDataApplet_SystemResources() { $oPalo = new paloSantoSysInfo(); $fastgauge = $this->_getFastGraphics(); $cpu_a = $oPalo->obtener_muestra_actividad_cpu(); $cpuinfo = $oPalo->getCPUInfo(); $speed = number_format($cpuinfo['CpuMHz'], 2) . " MHz"; $cpu_info = $cpuinfo['CpuModel']; $meminfo = $oPalo->getMemInfo(); //MEMORY USAGE $fraction_mem_used = ($meminfo['MemTotal'] - $meminfo['MemFree'] - $meminfo['Cached'] - $meminfo['MemBuffers']) / $meminfo['MemTotal']; $mem_usage_val = number_format(100.0 * $fraction_mem_used, 1); $mem_usage = $fastgauge ? $this->_htmlgauge($fraction_mem_used, 140, 140) : $this->genericImage('rbgauge', array('percent' => $fraction_mem_used, 'size' => '140,140'), null, null); $inf2 = number_format($meminfo['MemTotal'] / 1024, 2) . " Mb"; //SWAP USAGE $fraction_swap_used = ($meminfo['SwapTotal'] - $meminfo['SwapFree']) / $meminfo['SwapTotal']; $swap_usage_val = number_format(100.0 * $fraction_swap_used, 1); $swap_usage = $fastgauge ? $this->_htmlgauge($fraction_swap_used, 140, 140) : $this->genericImage('rbgauge', array('percent' => $fraction_swap_used, 'size' => '140,140'), null, null); $inf3 = number_format($meminfo['SwapTotal'] / 1024, 2) . " Mb"; //UPTIME $upfields = array(); $up = $oPalo->getUptime(); // Segundos de actividad desde arranque $upfields[] = $up % 60; $up = ($up - $upfields[0]) / 60; $upfields[] = $up % 60; $up = ($up - $upfields[1]) / 60; $upfields[] = $up % 24; $up = ($up - $upfields[2]) / 24; $upfields[] = $up; $uptime = $upfields[1] . ' ' . _tr('minute(s)'); if ($upfields[2] > 0) { $uptime = $upfields[2] . ' ' . _tr('hour(s)') . ' ' . $uptime; } if ($upfields[3] > 0) { $uptime = $upfields[3] . ' ' . _tr('day(s)') . ' ' . $uptime; } usleep(200000); $cpu_b = $oPalo->obtener_muestra_actividad_cpu(); $cpu_percent = calcular_carga_cpu_intervalo($cpu_a, $cpu_b); $cpu_usage = $fastgauge ? $this->_htmlgauge($cpu_percent, 140, 140) : $this->genericImage('rbgauge', array('percent' => $cpu_percent, 'size' => '140,140'), null, null); $inf1 = number_format($cpu_percent * 100.0, 1); $html = "<div style='height:165px; position:relative; text-align:center;'>\n <div style='width:155px; float:left; position: relative;'>\n {$cpu_usage}\n <div class=\"neo-applet-sys-gauge-percent\">{$inf1}%</div><div>" . _tr('CPU') . "</div>\n </div>\n <div style='width:154px; float:left; position: relative;'>\n {$mem_usage}\n <div class=\"neo-applet-sys-gauge-percent\">{$mem_usage_val}%</div><div>" . _tr('RAM') . "</div>\n </div>\n <div style='width:155px; float:right; position: relative;'>\n {$swap_usage}\n <div class=\"neo-applet-sys-gauge-percent\">{$swap_usage_val}%</div><div>" . _tr('SWAP') . "</div>\n </div>\n </div>\n <div class='neo-divisor'></div>\n <div class=neo-applet-tline>\n <div class='neo-applet-titem'><strong>" . _tr('CPU Info') . ":</strong></div>\n <div class='neo-applet-tdesc'>{$cpu_info}</div>\n </div>\n <div class=neo-applet-tline>\n <div class='neo-applet-titem'><strong>" . _tr('Uptime') . ":</strong></div>\n <div class='neo-applet-tdesc'>{$uptime}</div>\n </div>\n <div class='neo-applet-tline'>\n <div class='neo-applet-titem'><strong>" . _tr('CPU Speed') . ":</strong></div>\n <div class='neo-applet-tdesc'>{$speed}</div>\n </div>\n <div class='neo-applet-tline'>\n <div class='neo-applet-titem'><strong>" . _tr('Memory usage') . ":</strong></div>\n <div class='neo-applet-tdesc'>RAM: {$inf2} SWAP: {$inf3}</div>\n </div>"; return $html; }