Installing Nagios on the Raspberry Pi?

The Raspberry Pi’s low cost and small footprint make it an ideal platform for building a basic server to monitor your network and systems. Nagios is a widely used open-source monitoring application that can be installed on the Pi to provide detailed insight into your infrastructure’s status and performance.

Installing Nagios on the Raspberry Pi?

In this guide, we’ll walk through the full process of installing Nagios 4.4 on Raspberry Pi OS and optimizing the setup for effective monitoring and notification with minimal resource utilization.

Prerequisites and Planning

Before starting, ensure your Raspberry Pi meets these requirements:

  • Raspberry Pi 4 Model B or 3 Model B+ (2GB RAM minimum recommended)
  • 8GB+ microSD card loaded with Raspberry Pi OS
  • Network connectivity

You’ll also need:

  • A static IP address or DHCP reservation configured for your Pi
  • Port 80 open if you want to access the web interface from other devices

We’ll be compiling Nagios and its plugins from source, which requires installing dependencies like GCC and OpenSSL first.

Plan for the full installation process to take 30-60 minutes. Monitoring configuration can take further time depending on your infrastructure.

Install Nagios Dependencies

Connect to your Pi via SSH or the terminal. Update apt repositories and install compiler tools and Nagios dependencies:

sudo apt update

sudo apt install build-essential libgd-dev openssl libssl-dev unzip apache2 php wget libapache2-mod-php7.3

restart Apache to enable the PHP module:

sudo systemctl restart apache2

Compile and Install Nagios

With dependencies in place, we’re ready to compile and install Nagios 4.4 and the monitoring plugins.

Create a user and group for Nagios to run under:

sudo useradd nagios

sudo groupadd nagcmd

sudo usermod -a -G nagcmd nagios

Switch to this user and navigate to /opt:

sudo su – nagios

cd /opt

Download and extract the Nagios Core and Plugins files:

wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz

tar xzf nagios-4.4.6.tar.gz

wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.3.3.tar.gz

tar zxf release-2.3.3.tar.gz

Compile and install Nagios with these commands – when prompted about Apache configs, answer “Yes”:

cd nagioscore-nagios-4.4.6/

./configure

make all

make install

make install-init

make install-command mode

make install-config

make install-webconf

Repeat for the plugins:

cd ../nagios-plugins-release-2.3.3/

./tools/setup

./configure

make

make install

Configure the Web Interface

Nagios is now installed but needs additional setup for the web interface and configuration files.

In the Apache config directory, make a copy of Nagios config file to edit:

cd /etc/apache2/sites-available

sudo cp 000-default.conf nagios.conf

In nagios.conf update lines for ServerName, DocumentRoot, and directories:

ServerName localhost

DocumentRoot /usr/local/nagios/share

<Directory /usr/local/nagios/share>

    directives here

</Directory>

Alias /nagios /usr/local/nagios/share

<Directory /usr/local/nagios/share>

    auth and access directives 

</Directory>

Enable the new site and restart Apache:

sudo a2ensite nagios.conf 

sudo systemctl restart apache2

Nagios web interface can now be accessed at http://your-pi-ip/nagios with username nagiosadmin and the password you set during installation.

Configure Monitoring and Notifications

Out of the box Nagios is only set up to monitor the local Pi system. To extend monitoring to other devices and services:

  • Edit /usr/local/nagios/etc/objects/contacts. Cfg to add notification contacts
  • Edit /usr/local/nagios/etc/objects/commands.cfg to specify plugins for service checks
  • Create /usr/local/nagios/etc/objects/hosts.cfg to add hosts to monitor
  • Create /usr/local/nagios/etc/objects/services.cfg to define services to monitor on each host

See the Nagios documentation for configuration details.

Note: Nagios checks may be denied by firewalls. Ensure TCP port 5666 is open between your Nagios Pi and any hosts it monitors.

Restart the Nagios service after any major config changes:

sudo systemctl restart nagios

Optimizing Nagios on the Raspberry Pi

With a basic instance up, optimize Nagios by:

  • Tune the Apache config in nagios.conf to enhance performance.
  • Set notification batching in nagios.cfg to avoid sending a flood of alerts.
  • Increase the check result reaper timeout in nagios.cfg to compensate for the Pi’s slower processor.
  • Lower the parallel host check count in nagios.cfg. Reduce from default of 8 to 3-4.
  • Reduce CPU load with the monitoring log to decrease IO utilization.
  • Use remote plugin execution to offload checks from the Pi to monitored hosts.

Conclusion

With those steps complete, you now have a fully functional Nagios instance providing network and infrastructure monitoring on the Raspberry Pi. Don’t hesitate to dive deeper into the extensive configuration options as you add more infrastructure to monitor. Nagios on the Pi delivers tremendous visibility over your systems despite the platform’s modest cost and hardware.

Key Takeaways

  • The Raspberry Pi is capable of running Nagios for basic server monitoring
  • Compiling Nagios and plugins from source allows optimization for the Pi
  • Careful tuning of checking behavior, Apache, and logging is required
  • The Pi’s CPU and IO constraints limit total services vs desktop hardware

FAQS

  1. Can Nagios run on Pi OS Lite?
    No, the Apache web server and other dependencies require the standard Raspberry Pi OS desktop image.

  2. What login credentials are needed?
    The default admin user is nagiosadmin with the password set during Nagios compilation. Host/service authentication uses separate Nagios user accounts.

  3. How many hosts can a Pi monitor?
    A Pi 4 can reliably monitor 8-12 hosts depending on check frequency. Adjust parallel checks and other configs to reduce load if adding more hosts.

  4. What network ports must be open?
    At minimum, allow TCP port 80 access from monitoring clients to the Pi web UI. Also open TCP 5666 inbound to the Pi from all monitored hosts.

  5. Can Nagios monitor Windows servers?
    Yes, enable NRPE and install NSClient++ on Windows hosts to allow Nagios checks via the network.

  6. Does Nagios work without the web interface?
    Yes, but you would need to manage Nagios configurations at the CLI which is more difficult. The web UI vastly simplifies monitoring management.

  7. Can Nagios monitor cloud infrastructure?
    Nagios can monitor any IP-addressable infrastructure. Many cloud platforms offer integrations or plugins to bridge native APIs to Nagios’ network monitoring tools.

  8. Can the default admin credentials be changed?
    Yes, edit the htpasswd.users file at /usr/local/nagios/etc/ to change the Nagios admin username and password.

  9. What must be restarted after configuration changes?
    At minimum, run sudo systemctl restart nagios after any Nagios config changes. In some cases Apache may also need restarted with sudo systemctl restart apache2.

  10. How do I monitor SSH or HTTP availability?
    Enable the NRPE daemon on remote hosts. Then via SSH commands or HTTP queries in Nagios services config, check if those ports respond as expected.

  11. How can disk space checks be configured?
    Utilize the check_disk plugin and define a service check command specifying mount points to monitor space on.

  12. What interface does Nagios use for configurations?
    All core configuration is handled by editing plain-text .cfg files in the /usr/local/nagios/etc/ directories. The web UI offers simplified input forms for some objects.

  13. Does compiling Nagios for ARM processors help?
    Yes, enabling optimizations for ARM platforms like the Pi can provide noticeable improvements to Nagios performance relative to the x86 default compile.

  14. Can multiple Pi devices monitor different infrastructure?
    Absolutely. You can deploy independent Nagios instances on multiple Pis across business locations or cloud regions for example.

  15. How can I monitor Windows event logs?
    Use the NSClient++ check_eventlog plugin to track specific Windows event IDs and severity thresholds with Nagios.

  16. What Plugin thresholds indicate warnings vs critical states?
    Nagios convention is to define warning thresholds at about 60-75% of a metric maximum expected value. Critical thresholds are set in the 80-95% range depending on sensitivity.

  17. How do I customize the web interface?
    Edit /usr/local/nagios/etc/cgi.cfg to set options like default map view, status icons, row colors, and other display preferences. Custom CSS can also be applied.

  18. Can I enable SSH access to Nagios?
    Yes, enable SSH and copy your public key to /home/nagios/.ssh/authorized_keys to allow key-based SSH logins as the nagios user for CLI administration.

  19. What network protocols does Nagios use?
    Core Nagios traffic relies on TCP (ports 80, 5666) and basic Linux permissions. For remote checks, it often leverages ICMP, SSH, HTTP, DNS, SNMP, and custom plugins using TCP/UDP.

  20. Can Nagios monitor printer status?
    Yes, the check_printers plugin tests connections to CUPS managed printers. Or use SNMP checks to monitor printer hardware directly if devices support it.

Leave a Comment