How to monitor one FreeBSD server from another?

Hi,

I tried Googling this several ways but my searches always resulted in the answers to completely different problems, or third-party services. Maybe I wasn't phrasing it properly.

I have 2 FreeBSD servers in 2 different locations. I want them to monitor each other and email me if one or the other is down for more than 5 minutes. Is there an existing package to do this easily? Both are running FreeBSD 12.3.

thanks!
 
Monitor what, exactly? I don't mean that sarcastically, but is it enough that they can ping each other, or do you need to know specific service like a web server or a database server is running?

What does "is down" mean? Doesn't reply to ping? Can't ssh?

If really simple then writing your own script should do it, if a lot more complicated then there are packages that can help.

For servers I look after, I want to know the full "stack" is working, so I've made a simple monitoring system that makes a web request to each server, and that kicks off a small DB query. If the DB query returns a numeric value then I know all layers are working - networking, web server, database server, etc. Other people have more complex requirements and need to know response times, load averages, disk space, etc., etc., etc. And other people have simple requirements.

So really depends on what you are trying to achieve.
 
Monitor what, exactly? I don't mean that sarcastically, but is it enough that they can ping each other, or do you need to know specific service like a web server or a database server is running?

What does "is down" mean? Doesn't reply to ping? Can't ssh?

If really simple then writing your own script should do it, if a lot more complicated then there are packages that can help.

For servers I look after, I want to know the full "stack" is working, so I've made a simple monitoring system that makes a web request to each server, and that kicks off a small DB query. If the DB query returns a numeric value then I know all layers are working - networking, web server, database server, etc. Other people have more complex requirements and need to know response times, load averages, disk space, etc., etc., etc. And other people have simple requirements.

So really depends on what you are trying to achieve.
Yes, ping is fine. I just want to know if the server is alive at all.

I guess I could do something similar to what you describe. On one server, I could make a simple PHP script that runs with CRON. But what if I don't have a web server running on the other machine? Is there any pre-built package I can install that will ping the other server and email me if there is no response?

thanks
 
Do you want to do anything that's not in base? e.g. you mentioned PHP, but you should be able to do this with shell-scripting i.e. just use what's in a base FreeBSD install. I'm not a shell whiz so I can't tell you what the exact commands are!

Did you know that ssh can run commands on a remote server? So you could do something like this:

/usr/bin/ssh user@host2 hostname

And that would run the hostname command on the server "host2". You'd have to set up SSH keys to avoid password prompts, and it would need a bit of fiddling to work out how to best detect & handle a host being down.
 
Do you want to do anything that's not in base? e.g. you mentioned PHP, but you should be able to do this with shell-scripting i.e. just use what's in a base FreeBSD install. I'm not a shell whiz so I can't tell you what the exact commands are!

Did you know that ssh can run commands on a remote server? So you could do something like this:

/usr/bin/ssh user@host2 hostname

And that would run the hostname command on the server "host2". You'd have to set up SSH keys to avoid password prompts, and it would need a bit of fiddling to work out how to best detect & handle a host being down.
Thank you! I will look into this further, now that I know what to look for. I can do a little shell scripting but I need to learn more. I already have SSH keys set up because I use the second server as a backup using rsync.

I really want the backup server to check if the public web server is down and email me if it is. But it would be nice to know if the backup is alive too.
 
net-mgmt/nagios may be overkill for what you want, but it will do that, and can do a lot more if required.

"Nagios is a host and service monitor designed to inform you of network
problems before your clients, end-users or managers do. The monitoring
daemon runs intermittent checks on hosts and services you specify
using external "plugins" which return status information to Nagios.
When problems are encountered, the daemon can send notifications out
to administrative contacts in a variety of different ways (email,
instant message, SMS, etc.). Current status information, historical
logs, and reports can all be accessed via a web browser."

 
I really want the backup server to check if the public web server is down and email me if it is.
Have a look at "nc" (or even telnet) for the checking part.

The monitoring scripts I wrote are in PHP so that's definitely an option but it can be fun (maybe!) to see what you can do with the base tools and some scripting.
 
I have written a simple shell script for you.
Tune it as you want, save it somewhere,
and run it from non-root crontab every XX minutes.
Code:
#!/bin/sh
if ! ping -n -o -c 10 8.8.8.8 >>/dev/null
then echo "Ping failed! " | mail -s "ERROR: ping failed" admin@example.com
fi
Replace 8.8.8.8 with IP of your second server, and specify your email.
You must have configured MTA (sendmail/postfix/other) if you want to send e-mail from your own server.

P.S.
Ten years ago I used net-mgmt/smokeping - it was very useful for me. It is easy, but it need some time for setup.
 
Nagios works well, but is (more than) a little "naggy" (meaning more notifications than I really need). I usually prefer Xymon for routine system/service monitoring. Much more capable than the OP's stated need, but not that much harder to set up than a "simple shell script and cron job."
 
Back
Top