频率:' . $mhz[1][0]; $res['cpu']['cache'] = $cache[1][0]; $cache[1][0] = '
二级缓存:' . $cache[1][0]; $res['cpu']['bogomips'] = $bogomips[1][0]; $bogomips[1][0] = '
Bogomips:' . $bogomips[1][0]; $res['cpu']['model'][] = $model[1][0] . $mhz[1][0] . $cache[1][0] . $bogomips[1][0] . $x1; if (false !== is_array($res['cpu']['model'])) $res['cpu']['model'] = implode("
", $res['cpu']['model']); if (false !== is_array($res['cpu']['mhz'])) $res['cpu']['mhz'] = implode("
", $res['cpu']['mhz']); if (false !== is_array($res['cpu']['cache'])) $res['cpu']['cache'] = implode("
", $res['cpu']['cache']); if (false !== is_array($res['cpu']['bogomips'])) $res['cpu']['bogomips'] = implode("
", $res['cpu']['bogomips']); } return $res; } /** * 内存相关数据 * 单位为B * @return array|bool */ static public function getMenData() { if (false === ($str = @file("/proc/meminfo"))) return false; $str = implode("", $str); preg_match_all("/MemTotal\s{0,}\:+\s{0,}([\d\.]+).+?MemFree\s{0,}\:+\s{0,}([\d\.]+).+?Cached\s{0,}\:+\s{0,}([\d\.]+).+?SwapTotal\s{0,}\:+\s{0,}([\d\.]+).+?SwapFree\s{0,}\:+\s{0,}([\d\.]+)/s", $str, $buf); preg_match_all("/Buffers\s{0,}\:+\s{0,}([\d\.]+)/s", $str, $buffers); $res = array(); $res['memTotal'] = round($buf[1][0] / 1024, 2); $res['memFree'] = round($buf[2][0] / 1024, 2); $res['memBuffers'] = round($buffers[1][0] / 1024, 2); $res['memCached'] = round($buf[3][0] / 1024, 2); $res['memUsed'] = $res['memTotal'] - $res['memFree']; $res['memPercent'] = (floatval($res['memTotal']) != 0) ? round($res['memUsed'] / $res['memTotal'] * 100, 2) : 0; $res['memRealUsed'] = $res['memTotal'] - $res['memFree'] - $res['memCached'] - $res['memBuffers']; //真实内存使用 $res['memRealFree'] = $res['memTotal'] - $res['memRealUsed']; //真实空闲 $res['memRealPercent'] = (floatval($res['memTotal']) != 0) ? round($res['memRealUsed'] / $res['memTotal'] * 100, 2) : 0; //真实内存使用率 $res['memCachedPercent'] = (floatval($res['memCached']) != 0) ? round($res['memCached'] / $res['memTotal'] * 100, 2) : 0; //Cached内存使用率 $res['swapTotal'] = round($buf[4][0] / 1024, 2); $res['swapFree'] = round($buf[5][0] / 1024, 2); $res['swapUsed'] = round($res['swapTotal'] - $res['swapFree'], 2); $res['swapPercent'] = (floatval($res['swapTotal']) != 0) ? round($res['swapUsed'] / $res['swapTotal'] * 100, 2) : 0; //判断内存如果小于1G,就显示M,否则显示G单位 if ($res['memTotal'] < 1024) { $memTotal = $res['memTotal'] . " M"; $mt = $res['memTotal'] . " M"; $mu = $res['memUsed'] . " M"; $mf = $res['memFree'] . " M"; $mc = $res['memCached'] . " M"; //cache化内存 $mb = $res['memBuffers'] . " M"; //缓冲 $st = $res['swapTotal'] . " M"; $su = $res['swapUsed'] . " M"; $sf = $res['swapFree'] . " M"; $swapPercent = $res['swapPercent']; $memRealUsed = $res['memRealUsed'] . " M"; //真实内存使用 $memRealFree = $res['memRealFree'] . " M"; //真实内存空闲 $memRealPercent = $res['memRealPercent']; //真实内存使用比率 $memPercent = $res['memPercent']; //内存总使用率 $memCachedPercent = $res['memCachedPercent']; //cache内存使用率 } else { $memTotal = round($res['memTotal'] / 1024, 3) . " G"; $mt = round($res['memTotal'] / 1024, 3) . " G"; $mu = round($res['memUsed'] / 1024, 3) . " G"; $mf = round($res['memFree'] / 1024, 3) . " G"; $mc = round($res['memCached'] / 1024, 3) . " G"; $mb = round($res['memBuffers'] / 1024, 3) . " G"; $st = round($res['swapTotal'] / 1024, 3) . " G"; $su = round($res['swapUsed'] / 1024, 3) . " G"; $sf = round($res['swapFree'] / 1024, 3) . " G"; $swapPercent = $res['swapPercent']; $memRealUsed = round($res['memRealUsed'] / 1024, 3) . " G"; //真实内存使用 $memRealFree = round($res['memRealFree'] / 1024, 3) . " G"; //真实内存空闲 $memRealPercent = $res['memRealPercent']; //真实内存使用比率 $memPercent = $res['memPercent']; //内存总使用率 $memCachedPercent = $res['memCachedPercent']; //cache内存使用率 } $res['u_memTotal'] = $memTotal; $res['u_memTotal'] = $mt; $res['u_memUsed'] = $mu; $res['u_memFree'] = $mf; $res['u_memCached'] = $mc; //cache化内存 $res['u_memBuffers'] = $mb; //缓冲 $res['u_swapTotal'] = $st; $res['u_swapUsed'] = $su; $res['u_swapFree'] = $sf; $res['u_swapPercent'] = $swapPercent; $res['u_memRealUsed'] = $memRealUsed; //真实内存使用 $res['u_memRealFree'] = $memRealFree; //真实内存空闲 $res['u_memRealPercent'] = $memRealPercent; //真实内存使用比率 $res['u_memPercent'] = $memPercent; //内存总使用率 $res['u_memCachedPercent'] = $memCachedPercent; //cache内存使用率 return $res; } /** * 硬盘情况 * @return array */ static public function getDiskData() { $iTotal = round(@disk_total_space(".") / (1024 * 1024 * 1024), 3); //总 $iUsableness = round(@disk_free_space(".") / (1024 * 1024 * 1024), 3); //可用 $iImpropriate = $iTotal - $iUsableness; //已用 $iPercent = (floatval($iTotal) != 0) ? round($iImpropriate / $iTotal * 100, 2) : 0; $sDesc = ''; if($iPercent>85){ $sDesc =" 磁盘空间不多了,建议近期清理一下日志"; } if($iPercent>95){ $sDesc =" 磁盘空间快满了,可能会影响审计系统正常使用,建议立即清理日志"; } return array( 'iTotal' => $iTotal, 'iUsableness' => $iUsableness, 'iImpropriate' => $iImpropriate, 'iPercent' => $iPercent, 'sDesc' => $sDesc, ); } /** * 网接相关流量信息 */ static public function getInterfaceData() { //mii-tool $strs = @file("/proc/net/dev"); for ($i = 2; $i < count($strs); $i++) { preg_match_all("/([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $strs[$i], $info); $NetOutSpeed[$i] = $info[10][0]; //入网实时 $NetInputSpeed[$i] = $info[2][0]; //出网实时 $NetInput[$i] = self::formatsize($info[2][0]); //入网流量 $NetOut[$i] = self::formatsize($info[10][0]); //出网流量 } } /** * 单位自动转换 * @param $size * @return string */ static public function formatSize($size) { $danwei = array(' B ', ' K ', ' M ', ' G ', ' T '); $allsize = array(); $i = 0; for ($i = 0; $i < 5; $i++) { if (floor($size / pow(1024, $i)) == 0) { break; } } $allsize1 = array(); for ($l = $i - 1; $l >= 0; $l--) { $allsize1[$l] = floor($size / pow(1024, $l)); if (isset($allsize1[$l + 1])) { $allsize[$l] = $allsize1[$l] - $allsize1[$l + 1] * 1024; } } $len = count($allsize); $fsize = ""; for ($j = $len - 1; $j >= 0; $j--) { $fsize = $fsize . $allsize[$j] . $danwei[$j]; } return $fsize; }}?>