IT 개발/PHP
PHP 모니터링용 소스
행복구슬
2012. 5. 16. 18:04
1. PING 결과를 PHP로 받기
<?
$outputShel8 = shell_exec("ping -c2 -w2 125.137.163.168") ;
if(strpos($outputShell, '0 received'))
{
echo "<font color=blue>O</font>";
}
else
{
echo "<font color=red>X</font>";
}
?>
인자를 조절하면 여러개의 서버를 한번에 받을 수도 있다.
원문 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=351186#c_351186
2. 웹서버 응답 확인하기
http://10.10.10.10/response/response_php.php
에는 그냥 text로 "1번서버 정상!" 이렇게 출력하게 하고 모니터링 하는 페이지에서 다음과 같이 한다.
$str_php3 = file_get_contents('http://10.10.10.10/response/response_php.php');
if (strstr($str_php3,"정상") != "")
{
$STATUS = "NORMAL";
}
else
{
$STATUS = "CRITICAL";
}
이건 약간의 편한 방법이고 범용적인 경우는 다음 참고