Concerned about some of the devices connected to your network? Want to know when a web server goes offline? You need a network monitoring tool.

While several solutions are available, the Nagios should be your first port of call. Although paid versions of the software are available, Nagios offers an open source network monitor build for Raspberry Pi.

Why Set Up a Raspberry Pi as a Network Monitor?

Nagios Enterprise Monitoring Server (NEMS) can run on any Raspberry Pi model. But why not use a PC?

Raspberry Pi 4 makes an ideal network monitor

Well, it's a bit of a waste. Setting up a full system that is largely dedicated to pinging other devices wastes power, hardware, and physical space. The Raspberry Pi is a low-powered solution that takes up far less space and is a single piece of hardware.

Install Nagios Network Monitoring Tool on Raspberry Pi

You have two options for installing Nagios on your Raspberry Pi:

  1. You can install a full disk NEMS Linux image. This is the easy option, with all of the key pre-configuration you need for a quick start.
  2. Alternatively, why not manually install Nagios Core onto your existing Raspberry Pi environment?

Let's explore each in turn.

Easy: Install NEMS on the Raspberry Pi

For the easy install option, you need the following:

Related: How to Install an Operating System on Raspberry Pi

Due to hardware requirements, optimum NEMS performance is limited to the Raspberry Pi 3 and later. While you can use it with the older models, they're likely to perform far slower.

NEMS Linux for Raspberry Pi

Start by inserting the microSD card in your PC, then download NEMS and Etcher. With the software downloaded, install, and run Etcher.

  1. Select Flash from file
  2. The target drive should be automatically detected---if not, click Select target and browse to the SD card
  3. Click Flash to begin writing the disk image

Wait for the data to be written to the SD card and verified. Etcher will notify you when the process has completed. At this stage, safely remove the SD card from your PC, insert it into your Raspberry Pi and boot the computer. NEMS will first resize the filesystem before requiring some configuration.

On the prompt, enter

        sudo nems-init
    

Follow the steps to configure your locale and create an account.

Configure NEMS for Raspberry Pi network monitoring

You'll be ready to configure NEMS by opening https://nems.local in your browser. If this doesn't work, use the Pi's IP address instead.

NEMS Linux network monitor for Raspberry Pi

Hard: Manually Install Nagios Core on Raspberry Pi

To manually install Nagios on the Raspberry Pi, start with a Pi running Raspberry Pi OS on a 16GB or more microSD card.

Start by updating packages and upgrading:

        sudo apt update && sudo apt upgrade
    

Follow this with a reboot and install Nagios

        sudo reboot

sudo apt install nagios3

Once complete, you'll be prompted to set up an admin account, so keep a mental note of the password. You can login to Nagios from another device using your Pi's IP address, e.g. http://192.168.1.x/nagios3.

Related: Find Your IP Address in Linux

Configure Your Nagios Raspberry Pi Network Monitor

You're now ready to configure your network monitor. On the Pi, create a configuration file, monitor.cfg.

        sudo nano /etc/nagios3/conf.d/monitor.cfg
    

Here, add the details of the device you plan to monitor. For example, I have a game server and I want to know when it goes offline. In the configuration file, simply add the use, the host_name of the remote device, an alias, and IP address.

        define host {

use generic-host

host_name gameserver

alias gameserver

address 192.168.1.22

}

The defined template, generic-host, can be checked in /etc/nagios3/conf.d/generic-host_nagios2.cfg. Templates save time when you create device configurations, so take the time to check these.

When you're done with the CFG file, hit Ctrl + X then select Yes to exit. Reload Nagios:

        sudo service nagios3 reload
    

You can then keep an eye on your device via your chosen browser.

Related: How to Change the Keyboard Layout on Raspberry Pi

Configure Nagios Network Monitoring in the Browser

As well as text-based configuration you can set up network monitoring in Nagios using the browser interface with your Raspberry Pi.

This example shows you how to create a ping check to determine the status of a server or device:

  1. Click Nconf from the NagiosPi console
  2. Look in the left-hand column for Hosts
  3. To the right of this click Add
  4. Input the hostname, IP address and alias for the device you wish to monitor
  5. Click Submit when you're done
  6. Go to Services > Add
  7. Set Add additional services to host to check_ping and click Add
  8. Set the necessary delays (don't make them too short) and click Submit
  9. In the menu click Generate Nagios Config
  10. Click Deploy to complete
NEMS Linux network monitor for Raspberry Pi

When your device or website goes offline, Nagios will display its new status.

Monitoring Uptime and Status

With your monitoring configured, switch to the NagiosPi window and select Services. Here you'll see the device you added is being monitored alongside the others on your network. Each of these items can be clicked, as can the small icons that accompany each of them. By drilling down into each you discover more information about the device, and potentially get to the bottom of why it has gone offline.

This is the main screen that you should be using once your devices are setup in Nconf. Use it to keep an eye on your servers and network devices, and act accordingly when hardware goes offline.

Don't Get Lost in Your Raspberry Pi Network Monitor

By now you should have a good idea of the shape of your network. Nagios can be configured to alert you on all manner of events, but don't get carried away.

Once you start playing around with Nagios you'll discover a vast selection of options and configurations that can be setup. Nagios simplifies monitoring the state of a server or switch, but this is the tip of the iceberg. It's very easy to find yourself lost in a maze of options, potentially setting too many checks (possibly counter-productive).

So before proceeding, keep this in mind. Start slowly with Nagios, adding additional checks only after you've confirmed whether the first ones worked successfully.