Simple web server monitoring (alive)

16,640

Solution 1

You can use wget in a script like this

wget --timeout=3 --tries=1 --spider --no-check-certificate http://serverfault.com

if [ $? -ne 0 ];then
  echo "Site Down" | mail -s "Site Down" [email protected]
fi

And you will get an email if wget cannot access the site first time within three seconds.

Set up a cron job to run the script every few minutes.

There are many other alternatives but this is probably the simplest to set up from scratch.

Solution 2

You have many options, I'll give you two.

  • Nagios is a full-blown monitoring application capable of monitoring much much more than http, but it handles that as well. It can also create all kinds of repots ("Tell me the uptime percentage of our server/service X this week/month/year...")

  • Monit is another popular choice. Maybe not as feature-filled as Nagios, but nevertheless it's nice.

Solution 3

I've upvoted Richard and Janne's answer, but if you want some more detail as to what your webserver is sending and receiving, the first couple chapters of the O'Reilly book "Web Client Programming with Perl" by Clinton Wong gives a great overview of the HTTP protocol. If you want more detailed monitoring than just up/down and want to include response codes, etc, it is a fine place to start.

The book is old, but still valid. Published in 1997, O'Reilly has posted the contents of the book online for free at http://oreilly.com/openbook/webclient/ as part of their OpenBook initiative.

Solution 4

Well, if you want to run something yourself.

These are some options:

Or if you want a managed solution:

Personally I think Zabbix and Zenoss are overkill if you simply wish to monitor the status of a web server. But if you also plan to monitor anything else than they have more features than you'll ever need ;)

Share:
16,640

Related videos on Youtube

Zitrax
Author by

Zitrax

Updated on September 17, 2022

Comments

  • Zitrax
    Zitrax over 1 year

    Any tip about software to monitor if a web server is up and running on linux ? It should be able to run with not knowing anything more than the URL. And it must have functionality to send an email alert when the site goes down. Should not be hard to write a script for this myself but seems pointless if there is already something nice out there.

    Note that I am going to monitor internal servers, so this need to be a tool that runs on my machine on the same network, not external web based services.

    And note that small and simple solutions are preferred.

    Update: I eventually created a small python script that I am currently using for this, it can be found here.

  • Zitrax
    Zitrax almost 14 years
    I guess pingdom and uptrends can't monitor the sites on my internal network.
  • Geraint Jones
    Geraint Jones almost 14 years
    as long as you don`t run it on the server that its monitoring - you have no idea how often I have seen that done ;-)
  • Zitrax
    Zitrax almost 14 years
    I was looking for something small and simple, so monit seems closer to that.
  • Wolph
    Wolph almost 14 years
    @Zitrax: no, they can't. I read over that part.
  • Zitrax
    Zitrax over 13 years
    And without installing 'postfix' the mail command just silently fails to send.
  • Richard Holloway
    Richard Holloway over 13 years
    @Zitrax: And without wget being installed you will get an error. Without the network being up the wget will fail. Without the script being executable the cron job will fail and so on. Also I don't have 'postfix' installed and it works fine for me because I am using exim.
  • SDsolar
    SDsolar over 6 years
    Here is how to install ssmtp to use gmail: unix.stackexchange.com/questions/363814/…
  • SDsolar
    SDsolar over 6 years
    This is great. I monitor my cron log with wcron but had the screen shut off. So when my scp's to the hosting service (that happen every 10 minutes for sdsolarblog.com/montage ) were failing I didn't see it. In my case, mail can't reach the world, but ssmtp sure can,via gmail. So I will use this logic to send me a message as soon as the scp exits with a non-zero status. TNX MCH - Here is how to build wcron askubuntu.com/questions/966194/…
  • Avamander
    Avamander over 5 years
    Why the --no-check-certificate? Getting warned about broken TLS deployment is also valuable information.