9

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
  • 784
  • 2
  • 11
  • 21
  • possible duplicate of [what are the various ways to monitor servers remotely.](http://serverfault.com/questions/152226/what-are-the-various-ways-to-monitor-servers-remotely) – Warner Aug 31 '10 at 14:19
  • See also: http://serverfault.com/questions/44/what-tool-do-you-use-to-monitor-your-servers -- This topic has been covered extensively on a high level. – Warner Aug 31 '10 at 14:20

8 Answers8

14

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" admin@yourdomain.com
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.

Zitrax
  • 784
  • 2
  • 11
  • 21
Richard Holloway
  • 7,256
  • 2
  • 24
  • 30
  • 7
    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 ;-) – Geraint Jones Aug 31 '10 at 10:47
  • Thanks. In addition I found that --spider is also an useful option as it avoids to actually save the page to disk. – Zitrax Sep 01 '10 at 10:16
  • 2
    And without installing 'postfix' the mail command just silently fails to send. – Zitrax Sep 02 '10 at 08:02
  • 3
    @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. – Richard Holloway Sep 02 '10 at 15:45
  • I would add --no-proxy and --spider – Filippo Vitale Mar 29 '12 at 01:25
  • Here is how to install ssmtp to use gmail: https://unix.stackexchange.com/questions/363814/simplest-way-to-send-one-line-mail-out-via-command-line-using-gmail/363815#363815 – SDsolar Nov 04 '17 at 05:10
  • 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 https://www.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` https://askubuntu.com/questions/966194/16-04-how-do-i-make-cron-create-cron-log-and-monitor-it-in-real-time/966195#966195 – SDsolar Nov 04 '17 at 05:15
  • 1
    Why the `--no-check-certificate`? Getting warned about broken TLS deployment is also valuable information. – Avamander Jan 29 '19 at 11:08
7

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.

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
1

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 ;)

Wolph
  • 865
  • 1
  • 7
  • 12
1

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.

gWaldo
  • 11,887
  • 8
  • 41
  • 68
0

I would vote up Janne's answer if I had rep.

Important note about Nagios, the fact that it's full blown does not mean it's a hard and long installation, It's quite simple and friendly.

Second thing, you should really check out what your hardware vendor has to offer. For example, I'm using HP Proliants and they have really nice rpm's that help.

bangolio
  • 21
  • 1
0

If you like what Nagios does, but don't want to delve into the internals, you can also check out Opsview. It is Nagios and a couple of other tools, but delivered through a nice GUI. It's a pretty good starting point.

SystemParadox
  • 827
  • 9
  • 14
0

I would agree that Nagios is a great software but if you want a freeware I would suggest you to take a look at AppPerfect Agentless Monitor. Linux Server Monitoring with AppPerfect is extremely lightweight and adds negligible overhead to target system while monitoring. You can monitor all the important statistics related to CPU, disk, network and memory using this tool. Setup is very simple and the software is very easy to use. A clear documentation and tutorial is also available here for Linux server monitoring

0

One solution I've been using is HashiCorp's consul.

It certainly is more than a simple script with email output, but setting up the kind of monitoring you are talking about is still very easy (a few lines of YAML or JSON).

You would most likely create a template, but monitoring a single server could be done as follows:

{
  "service": {
    "name": "web", 
    "tags": ["production"], 
    "port": 80,
    "check": {
      "id": "front-end",
      "name": "HTTP front-end for web service",
      "http": "http://web.domain.tld",
      "interval": "10s",
      "timeout": "1s"
    }
  }
}

One reason for suggesting it is that it does allow you to go beyond monitoring 'just' the web front-end if you want to, and also allows you to group checks by service (e.g. your report_server service could have a check for the web front-end, one for the web back-end, and one for the primary DB, all of which would provide alerts tied to this one service).

iwaseatenbyagrue
  • 3,588
  • 12
  • 22