Hello friends,

          I am desperatly in need of a script that can monitor my website and alerts me through an email when its down, Down in the sense not only the webserver or the machine but when the page returns  other than my webpage content such as 500 internal server or page cannot be displayed error messges etc.... I am running a site with apache 1.3 . php 4 and RHEL 3, My users offen complains me that they are getting error messages whan they try to send a mail or something else , But i am unnotified by anything that occurs to my site and my respose time is also getting delayed of this , I just want to notified when anything goes unexpectedly with my site , So that i can see and rectifify it  before by users get frustrated.

I believe i would get a solution from you guys ..

Thanks,

mahesh

    You do realize that such a script needs to run on another server, not the server you are trying to monitor? Do you have such a server available?

    The script itself is very easy to build in PHP. In pseudo code:

    $content = file_get_contents("http://yourserver/check.php");
    if($content != 'expected content) {
      mail('webmaster@yourserver', 'Serverdown', 'Just to let you know.');
    }
    

    Just schedule this script to run every minute or so in a crontab.

    In check.php on your server you could just put a plain HTML file or you could include some database connection logic so to test the running of your database server as well.

    A side effect of this construction is that there will be a line in your access log everytime the script checks the server. This could lead to "stat polution", so if you process your logfiles into stats, I would filter out any access to the check.php page.

      If you can use .htaccess you can create custom error pages and make them email you.

        HalfaBee wrote:

        If you can use .htaccess you can create custom error pages and make them email you.

        This will not work if Apache is not running or if the server is completely down, or if the network to which the server is connected has problems etc.

          ... but when the page returns other than my webpage content such as 500 internal server or page cannot be displayed error messges ...

          Of course it won't work if the server is not running, but it would report 500 or 404 errors etc which might not be picked up by checking one file.

            mjax wrote:

            You do realize that such a script needs to run on another server, not the server you are trying to monitor? Do you have such a server available?

            The script itself is very easy to build in PHP. In pseudo code:

            $content = file_get_contents("http://yourserver/check.php");
            if($content != 'expected content) {
              mail('webmaster@yourserver', 'Serverdown', 'Just to let you know.');
            }
            

            Just schedule this script to run every minute or so in a crontab.

            In check.php on your server you could just put a plain HTML file or you could include some database connection logic so to test the running of your database server as well.

            A side effect of this construction is that there will be a line in your access log everytime the script checks the server. This could lead to "stat polution", so if you process your logfiles into stats, I would filter out any access to the check.php page.

            Dear mjax,

                  Thanks for your  reply, I do realize that i need ro run this script from another server and i do have one. Can i use this script to monitor applications that are running in JAVA also..

            Thanks,

            mahesh

              I wrote this post some time back when I needed to monitor one server from another, bubblenut posted some great feedback you could take into account.

                Write a Reply...