public function check() { $arrRes = Utils::get_cmd_res('ulimit -c'); if ($arrRes[0] === '0') { Utils::print_error("没有打开coredump设置"); return; } $arrRes = Utils::get_cmd_res('cat /proc/sys/kernel/core_pattern'); $pattern = $arrRes[0]; if (empty($pattern)) { return; } $dir_name = dirname($pattern); if ($dir_name === '.') { return; } if ($handle = @opendir($dir_name)) { $msg = ''; $delimiter = ''; while (false !== ($entry = readdir($handle))) { if ($entry == '.' || $entry == '..') { continue; } $msg .= "{$delimiter}corefile: {$entry} "; $delimiter = "\n"; } Utils::print_error($msg); closedir($handle); } }
public function check() { $c_user = Utils::get_current_uname(); if ($c_user != 'root') { Utils::print_error("'" . __CLASS__ . "' need root privilege to run check"); return; } $arrRes = Utils::get_cmd_res_split(" ps -efH | grep php-cgi | grep -v grep | awk '{print \$2}'"); unset($arrRes[0]); $stack = array(); foreach ($arrRes as $val) { $cmd = "pstack {$val[0]} | head -1 | awk '{print \$4}'"; $hang_fun = Utils::get_cmd_res($cmd); $stack[] = $hang_fun[0]; } $cnt_val = array_count_values($stack); arsort($cnt_val); $sum_process = count($arrRes); foreach ($cnt_val as $key => $val) { if ($key == '__accept_nocancel') { continue; } if ($val * 2 >= $sum_process) { $msg = "php process hang on system function '{$key}' "; Utils::print_error($msg); } } }
public function check() { /*----------检查磁盘空间-------------*/ $cmd = "df -h"; $arrRes = array(); exec($cmd, $arrRes); unset($arrRes[0]); foreach ($arrRes as $val) { $val = Utils::split_line_space($val); if ($val[4] == '100%') { $msg = 'space:' . $val[0] . "\t" . $val[4]; Utils::print_error($msg); } } /*----------检查inode使用-------------*/ $cmd = "df -i"; $arrRes = array(); exec($cmd, $arrRes); unset($arrRes[0]); foreach ($arrRes as $val) { $val = Utils::split_line_space($val); if ($val[4] == '100%') { $msg = 'inode:' . $val[0] . "\t" . $val[4]; Utils::print_error($msg); } } }
public function check() { $cmd = "ps -ef | grep 'php-cgi' | grep -v grep | wc -l"; $arrRes = Utils::get_cmd_res($cmd); $php_num = intval($arrRes[0]); if ($php_num == 0) { $msg = "there are no php process"; Utils::print_error($msg); } }
public function check() { $cmd = "ps -ef | grep 'nginx: worker process' | grep -v grep | wc -l"; $arrRes = Utils::get_cmd_res($cmd); $nginx_num = intval($arrRes[0]); if ($nginx_num == 0) { $msg = "there are no nginx process"; Utils::print_error($msg); } }
public function check() { $cmd = "netstat -n | grep SYN_RECV | wc -l"; $arrRes = Utils::get_cmd_res($cmd); $syc_recv_num = intval($arrRes[0]); if ($syc_recv_num > 10) { $msg = "SYN_RECV status num : {$syc_recv_num}, there may be a syn flood attack"; Utils::print_error($msg); } }
public function check() { $arrRes = Utils::get_cmd_res('ulimit -n'); $max_open_file = intval($arrRes[0]); $arrRes = Utils::get_cmd_res_split('sar -v 1'); $open_file = $arrRes[3][2]; if ($open_file * 100 / $max_open_file > 30) { $msg = "open file handle num : {$open_file}, max open handle num : {$max_open_file}"; Utils::print_error($msg); } }
public function check() { $arrRes = Utils::get_cmd_res(' mpstat -P ALL | wc -l'); $cpu_num = $arrRes[0] - 4; $arrRes = Utils::get_cmd_res_split('uptime'); $load_one_minute = trim($arrRes[0][7], ' ,'); if ($load_one_minute > 2 * $cpu_num) { $msg = "cpu number: {$cpu_num}, load in 1 minute: {$load_one_minute}"; Utils::print_error($msg); } }
public function checkStatus($log_line, $log_format) { $index = $log_format['$status']; $status = array(); foreach ($log_line as $val) { $status[$val[$index]]++; } if ($status[200] != count($log_line)) { $msg = "http status num :\n" . var_export($status, true); Utils::print_error($msg); } }
public function check() { $php_server_port = lnmpConfig::PHP_SERVER_PORT; $cmd = "netstat -n | grep ESTABLISHED | awk '{print \$4}' | grep :{$php_server_port} | wc -l"; $arrRes = Utils::get_cmd_res($cmd); $concurrency = intval($arrRes[0]); //并发度 if ($concurrency * 1000 > lnmpConfig::REQUEST_TIME_COST * lnmpConfig::SERVER_THROUGHPUT) { $msg = "the php connections is too many , connections: {$concurrency} , time_cost : " . lnmpConfig::REQUEST_TIME_COST . "ms, throughput :" . lnmpConfig::SERVER_THROUGHPUT . "qps"; Utils::print_error($msg); } }
public function check() { $web_server_port = lnmpConfig::WEB_SERVER_PORT; $cmd = "netstat -n | grep ESTABLISHED | awk '{print \$4}' | grep :{$web_server_port} | wc -l"; $arrRes = Utils::get_cmd_res($cmd); $concurrency = intval($arrRes[0]); //并发度,不活跃进的连接也算作了并发度,在繁忙的服务器上,连接一般都是活跃的,所以误差不会很大, 长连接除外。 if ($concurrency * 1000 > lnmpConfig::REQUEST_TIME_COST * lnmpConfig::SERVER_THROUGHPUT) { $msg = "the server connections is too many , connections: {$concurrency} , time_cost : " . lnmpConfig::REQUEST_TIME_COST . "ms, throughput :" . lnmpConfig::SERVER_THROUGHPUT . "qps"; Utils::print_error($msg); } }
public function check() { $arrRes = Utils::get_cmd_res_split('free'); $total = $arrRes[1][1]; $free = $arrRes[2][3]; $use_ratio = round(($total - $free) * 100 / $total, 1); if ($use_ratio > 80) { $used = $total - $free; $total = round($total / 1024, 0); $used = round($used / 1024, 0); $free = round($free / 1024, 0); $msg = "Memory, total: {$total}M, used:{$used}M, free:{$free}M, {$use_ratio}% used"; Utils::print_error($msg); } //是否要加下swap使用率 }
public function check() { $arrRes = Utils::get_cmd_res_split('iostat -d -x 1 2'); //计算最近的1s IOWAIT也在这里查看 for ($i = 6;; $i++) { $hd = $arrRes[$i]; if (empty($hd[0])) { break; } if ($hd[11] >= 20) { $msg = "{$hd[0]} : {$hd[11]}, percentage of CPU time during which I/O requests were issued to the device, the IO is too high"; Utils::print_error($msg); } $await = $hd[9]; $svctm = $hd[10]; if ($await > 5 * $svctm) { $msg = "await : {$await}, svctm:{$svctm}, the await time is greater than svctm much more, the IO is too high"; Utils::print_error($msg); } } }
public function check() { $arrRes = Utils::get_cmd_res_split('vmstat 1 2'); //计算最近的1s IOWAIT也在这里查看 $idle = $arrRes[3][14]; if ($idle < 20) { $msg = "idle:{$idle}"; Utils::print_error($msg); } $wa = $arrRes[3][15]; if ($wa > 10) { $msg = "cpu wa:{$wa}, too many time spent waiting for IO"; // iostat -x %util也会相应的高 Utils::print_error($msg); } $si = $arrRes[3][6]; $so = $arrRes[3][7]; if ($si >= 200 || $so >= 200) { $msg = "si: {$si} , so: {$so} , the swap rate is too high, may not have enough memory"; Utils::print_error($msg); } }
public function check() { $mysql_info = lnmpConfig::$mysql_info; $link = mysql_connect($mysql_info['host'] . ':' . $mysql_info['port'], $mysql_info['user'], $mysql_info['pass']); if ($link === false) { $msg = "Failed to connect to MySQL: " . mysql_error(); Utils::print_error($msg); exit; } $result = mysql_query("show processlist;"); $sum_cnt = 0; $no_sleep_cnt = 0; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($line['Command'] != 'Sleep') { $no_sleep_cnt++; } $sum_cnt++; } if ($sum_cnt > 3 && $no_sleep_cnt * 5 > $sum_cnt) { $msg = "Too many mysql threads is running"; Utils::print_error($msg); } }
public function check() { /********网络流量检测*******/ $arrRes = Utils::get_cmd_res_split('sar -n DEV 1'); for ($i = 3;; $i++) { $IFACE = $arrRes[$i][1]; if (empty($IFACE)) { break; } $rxbyt = $arrRes[$i][4]; $txbyt = $arrRes[$i][5]; $speed = $this->getNetCardSpeed('IFACE'); if ($rxbyt * 100 / $speed > 80) { $msg = "{$IFACE} received speed : {$rxbyt} byte/s, net card speed: {$speed} byte/s"; Utils::print_error($msg); } if ($txbyt * 100 / $speed > 80) { $msg = "{$IFACE} send speed : {$rxbyt} byte/s, net card speed: {$speed} byte/s"; Utils::print_error($msg); } } /********网络错误检测*******/ $arrRes = Utils::get_cmd_res_split('sar -n EDEV 1'); for ($i = 3;; $i++) { $IFACE = $arrRes[$i][1]; if (empty($IFACE)) { break; } $rxerr = $arrRes[$i][2]; $txerr = $arrRes[$i][3]; $coll = $arrRes[$i][4]; $rxdrop = $arrRes[$i][5]; $txdrop = $arrRes[$i][6]; $txcarr = $arrRes[$i][7]; $rxfram = $arrRes[$i][8]; $rxfifo = $arrRes[$i][9]; $txfifo = $arrRes[$i][10]; if ($rxerr > 10) { $msg = "{$IFACE} Total number of bad packets received per second: {$rxerr}"; Utils::print_error($msg); } if ($txerr > 10) { $msg = "{$IFACE} Total number of errors that happened per second while transmitting packets: {$txerr} , there are some wrong with the net "; Utils::print_error($msg); } if ($coll > 10) { $msg = "{$IFACE} Number of collisions that happened per second while transmitting packets: {$coll}"; Utils::print_error($msg); } if ($rxdrop > 10) { $msg = "{$IFACE} Number of received packets dropped per second because of a lack of space in linux buffers: {$rxdrop} "; Utils::print_error($msg); } if ($txdrop > 10) { $msg = "{$IFACE} Number of transmitted packets dropped per second because of a lack of space in linux buffers: {$txdrop} "; Utils::print_error($msg); } if ($txcarr > 10) { $msg = "{$IFACE} Number of carrier-errors that happened per second while transmitting packets: {$txcarr} "; Utils::print_error($msg); } if ($rxfram > 10) { $msg = "{$IFACE} Number of frame alignment errors that happened per second on received packets: {$rxfram} "; Utils::print_error($msg); } if ($rxfifo > 10) { $msg = "{$IFACE} Number of FIFO overrun errors that happened per second on received packets: {$rxfifo} "; Utils::print_error($msg); } if ($txfifo > 10) { $msg = "{$IFACE} Number of FIFO overrun errors that happened per second on transmitted packets: {$txfifo} "; Utils::print_error($msg); } } }