How to use Raspberry Pi to monitor network? (Nagios)

install nagios raspberry pi

Today I wanted to use my Raspberry Pi to monitor my network with Nagios
But I was lost trying to find out what was the best option to do this.
I saw a lot of how-to guides about NEMS, Nagios3 but nothing perfect with the lastest Nagios version
I’ll explain here what I found and how to do the same step by step

How to use Raspberry Pi to monitor network?
The best way to monitor your network with your Raspberry Pi is to use a software called Nagios
Nagios is like a failure detector, it will check one thing regularly (like every 5 minutes) and alert you when this check doesn’t work as expected

In this post I’ll explain how to install Nagios on your Raspberry Pi in order to check your network status
But I’ll start by listing all the ways to get Nagios I found on Internet and to show you why most of them are useless or unsuitable

What is the best way to get Nagios on Pi?

I’ll start this post by explaining you what I found to get Nagios quickly on the Raspberry Pi, and why they are bad options for you


My first search showed me “NagiosPi”
I was excited to see that Nagios created a specific version for the Raspberry Pi
This is the main reason that led me to install it on my Pi
But I was quick cooled, seeing this is a side project, with no update since 2013

This was not suitable for me, I know that Nagios releases new updates at least once a year, so I want something recent


Next step, I looked into apt repository what I could get
Did the guy from NagiosPi stopped his project because Raspbian added the Nagios package in apt?
Maybe, but I only find Nagios 3 in the apt sources, the lastest version when I wrote this line was Nagios 4.4.2

It could be the easiest way to get Nagios, but I want the lastest version or not too far from it


Next search, I found a pre-configured SD card with Nagios and a lot of monitoring tools
This is the NEMS Linux project, NEMS stands for Nagios Enterprise Monitoring Server
Seems interesting no?

Yes, I tried it, but this was not suitable for Raspberry Pi
Even when doing nothing, I have a lot of load, and couldn’t do anything without lag
Maybe too much tools for the Raspberry Pi

load average on nems

From sources?

The last option I was thinking about was to install Nagios manually from the sources
But I thought this will be difficult and time consuming to compile everything

Hum … not so long finally, maybe 30min to get everything working with the lastest version
So for me, it’s really the best option I found, and I’ll now explain to you how to install it on your Raspberry Pi

How to install Nagios on your Raspberry Pi?

Install Raspbian

First thing you need, is an operating system 🙂
Start with Raspbian, I think Raspbian Lite is perfect for this goal, but take the Desktop version if you prefer

Here are the first steps you need to complete before going further:

That’s it, we are ready to start

Downloads and prerequisites

Nagios is a web interface, so we need to install Apache and PHP

sudo apt install apache2 libapache2-mod-php

Then there are two things we need to download and install:

  • Nagios Core: It’s the main part of the Nagios system
  • Nagios Plugins:  This will add basic check commands to Nagios, so you’ll not have to create all the scripts yourself

We need to download sources for them, check their websites for the lastest version:
Nagios Core downloads
Nagios Plugins downloads

Finally, download archives with wget:

mkdir /home/pi/Downloads
cd /home/pi/Downloads

Now we are ready to move to the installation process

Install Nagios

Create Nagios user and group

We need to create a specific user for Nagios, and a group for nagios and apache users (nagcmd)

sudo useradd -m -s /bin/bash nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data

Compile and install nagios

Now we have to extract files from the archive, compile the sources and install Nagios on the Raspberry Pi

  • Move to the downloads directory
    cd /home/pi/Downloads
  • Extract files from the archive downloaded before
    tar zxvf nagios-4.4.2.tar.gz

    Don’t forget to change the version number if you download another one

  • Compile
    cd nagios-4.4.2/
    ./configure --with-command-group=nagcmd
    make all

    This could take a few minutes

  • Install
    sudo make install
    sudo make install-init
    sudo make install-config
    sudo make install-commandmode

This is the end of the Nagios core installation
We now need to configure the Apache part to allow access to the Nagios page

Apache configuration for Nagios

  • Enable the CGI module for Apache
    sudo a2enmod cgi
  • Copy the Apache configuration to the Apache folder
    sudo cp sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf
  • Create the first user for the web interface
    sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  • Restart Apache
    sudo service apache2 restart
  • Check if you have access to Nagios
    Go to http://<RASPBERRY IP>/nagios
    You should get something like this:
    nagios not running raspberry pi
    It’s normal, we’ll fix that now

The Nagios installation is almost done, we just need to run the Nagios service

Start the Nagios service

Nagios has a service running in background to launch a check at a pre-defined frequency (every 5min for example)
We need to start it to finish the installation:

sudo service nagios start

And to start Nagios automatically on boot:

sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

If you refresh the web interface, you should now see “Daemon running with PID XXX”
Everything is fine with Nagios, we just want to add plugins now

Install Nagios Plugins

Follow this procedure to install the Nagios plugins:

  • Extract files from the archive
    tar zxvf nagios-plugins-2.2.1.tar.gz
  • Compile and install
    cd nagios-plugins-2.2.1/
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    sudo make install

All plugins are now available in the /usr/local/nagios/libexec/ folder and ready to use in Nagios

You may need to restart Nagios to apply changes:

sudo service nagios restart

How to configure Nagios to fit your needs?

Nagios vocabulary

Nagios uses a specific vocabulary to define each object in the configuration
So first, I have to be sure you know it:

  • Command: a command is basically a script from the Nagios plugins folder, we define it in Nagios to use it later with parameters (ex: check_load is a command)
  • Service: a service is a check that applies to one or more computers, and that uses a command to run a particular verification (ex: check if the load is above 10 on Raspberry Pi is a service)
  • Host: a host is a computer, a server, anything with an IP address
  • Hostgroup: you can define a host group, like “Raspberry Pi”, and apply the same services to all the hosts inside this group

We’ll now see how to configure each one in the Nagios configuration file
For the example I’ll monitor my Raspberry Pi Zero from the Raspberry Pi 3B+ where Nagios is installed

Prepare the host

Nagios uses mainly SNMP to connect to other hosts and get all informations needed
So we need to install SNMP on every new host before adding it in the configuration file

This is not mandatory, it depends on which services you’ll create for this host
Anyway, I’ll show you how to do it, so you have a complete tutorial

In my case, I followed these steps on the Raspberry Pi Zero:

  • Connect to the host via SSH
  • Install snmpd
    sudo apt install snmpd
  • Move to the configuration folder
    cd /etc/snmp
  • Remove (or backup) the snmpd.conf file
    sudo rm snmpd.conf
  • Create a new snmpd.conf file
    sudo nano snmpd.conf
  • Paste these lines into
    com2sec readonly default RASPBERRYTIPS
    group MyROGroup v1 readonly
    group MyROGroup v2c readonly
    view all included .1 80
    access MyROGroup "" any noauth exact all none none
    sysName Pi Zero

    Replace RASPBERRYTIPS by the community you want to use
    Replace sysName by your host name or description
    There is a lot of options available in snmpd.conf, but for this test we don’t need more than that

  • Save and exit (CTRL+O, CTRL+X)
  • Restart snmpd
    sudo service snmpd restart

We can now add this host in Nagios

Add a host

  • Go back to the Raspberry Pi hosting Nagios
  • Move to the objects configuration folder of Nagios
    cd /usr/local/nagios/etc/objects
  • Create a new file for your host, like pizero.cfg
    sudo nano pizero.cfg
  • Paste these lines into
    define host {
        use                     linux-server            ; Host group to use
        host_name               Pi Zero                 ; Name of this host
        alias                   pizero                  ; Alias
        address                   ; IP Address

    This is really a basic host definition, with the host name, alias and IP address
    We also add it to the Linux servers host group to inherit group-defined services if you add some later

  • Save and exit (CTRL+O, CTRL+X)
  • Now we need to tell Nagios that we added a new file
    Add this line in /usr/local/nagios/etc/nagios.cfg (just under localhost.cfg will be perfect)
  • Restart Nagios
    sudo service nagios restart
  • Go back to the Nagios web interface, in the Hosts menu
    You should have a new line like this
    nagios add host

Nagios already monitors the ping response for our new host, but we want more
So we need to add a service inside, but first we need to define the command to use

Add a command

Previously in this tutorial you downloaded and installed Nagios plugins
Nagios plugins provide a lot of commands to check the local host, but not so much for remote hosts
You can also download a lot of other commands on this website (specifically look for SNMP plugins)

For this example I’ll monitor the time synchronization between my two Raspberry Pi

To add a command in Nagios, follow these steps:

  • Move to the plugins folders
    cd /usr/local/nagios/libexec
  • Run the command without parameters
  • Note the help message, and parameters you need to pass
    In my case I got this error message:
    check_ntp -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-4|-6] [-v verbose]

    So, I know I have to specify the host IP in the -H argument
    And maybe a warning and critical threshold with -w and -c
    Other options don’t seem relevant for me

  • Open the commands configuration file
    sudo nano /usr/local/nagios/etc/objects/
  • Check if your command is already inside and if not, you have to add it like this:
    define command {
        command_name    check_ntp
        command_line    $USER1$/check_ntp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
  • Save, exit and restart Nagios
    sudo service nagios restart
  • Check that your command is now available in Nagios
    • Go to the web interface
    • Click on “Configuration” in the left menu
    • Choose “Commands” is the list and click “Continue”
    • You should now see “check-ntp” in the list (or any command you add)

The command is now ready to be used for your host, but we need to create a new service to apply it

Add a service

To create a new service, follow these steps:

  • Open your host configuration file
    sudo nano /usr/local/nagios/etc/objects/pizero.cfg

    Adapt the filename to what you have created before

  • Paste these lines
    define service {
        use                     local-service           ; Name of service template to use
        host_name               Pi Zero
        service_description     Time synchronization
        check_command           check-ntp!1!5

    Don’t forget to adapt these lines to your previous configuration
    On the check_command line, we define all arguments, separated by exclamation points

  • Save and exit
  • Check your configuration
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    This could be useful to know if you have configuration errors before restarting Nagios
    In my case I wrote check_ntp instead of check-ntp 🙂

  • Restart Nagios
    sudo service nagios restart

Now in the status detail from your host you should see the new service

nagios service detail

If you understood how to create a host, a command and a service, you are now ready to do anything in Nagios
Feel free to download new plugins on Internet, or even code your own plugins (it’s nothing more than a basic script to check something)

Related questions

Is it possible to create the configuration from the web interface?  Unfortunately no, Nagios doesn’t provide a configuration tool in the Core version. But there are several configuration tools you could install. The one I often use is Thruk, I didn’t try it yet on Raspberry Pi, but you can download it here if you want

Is it possible to monitor Windows or other hosts? Yes. You could monitor anything on the network. SNMP is also available for Windows and most of the network equipments (router, switch, home automation device, …).  As you can create your own check commands, everything is possible.


That’s it, you know how to install and configure a Nagios server on your Raspberry Pi to monitor your network or anything you want
With this tutorial, you get the lastest Nagios version, with no excessive load average (currently 0.00 on my Pi ^^)

Once Nagios is installed, it’s not really different from any Nagios server on Linux
So feel free to check Linux tutorials for advanced configuration

Today I wanted to use my Raspberry Pi to monitor my network with Nagios But I was lost trying to find out what was the best option to do this. I saw a lot of how-to guides about NEMS, Nagios3 but nothing perfect with the latest Nagios version I’ll explain here what I found and how to do the same


  1. dabance Reply

    Getting the following error while opening http:///nagios

    Nagios Core

    <frame src="” name=”main” frameborder=”0″ style=””>

    Nagios Core
    Copyright © 2010- Nagios Core Development Team and Community Contributors.
    Copyright © 1999-2010 Ethan Galstad

    Note: These pages require a browser which supports frames

  2. RaspberryTips Post authorReply

    Hi dabance,

    This message doesn’t help
    Can you paste the exact error message? Or a screenshot maybe?


  3. jamesH Reply

    Thank you for the excellent guide.
    Sadly, I’m having trouble installing the nagios plugins because a whole bunch of pre-requisites are missing.
    From the nagios install webpage, there are a bunch of yum packages (which the raspberry pi doesn’t have):

    yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
    yum install -y perl-Net-SNMP

    Looks like I need to find some equivalents for apt-get…

  4. jamesH Reply

    I just needed to install gettext:
    apt-get install gettext
    … splendid! Thanks again 🙂

  5. Tommie Rowell Reply


    When attempting to do the following step:

    sudo cp sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

    I get the following error:

    cp: cannot stat ‘sample-config/httpd.conf’: No such file or directory

    Which step creates this file? Or should it have been on my system already? I am on a Raspberry Pi 3 B+

  6. G3n3r4l_Murloc Reply

    Hello Thank you for the guide,
    I am having trouble runnning Nagios.

    I don’t have installed plug-in because before that, when I am accessing to my Nagios web page.
    It says : Nagios Core Not running,
    I check the status of nagios service and nothing special appears :

    ● nagios4.service – LSB: nagios host/service/network monitoring and management system
    Loaded: loaded (/etc/init.d/nagios4; generated)
    Active: active (running) since Mon 2019-07-29 19:15:26 CEST; 13min ago
    Docs: man:systemd-sysv-generator(8)
    Process: 2388 ExecStart=/etc/init.d/nagios4 start (code=exited, status=0/SUCCESS)
    Tasks: 8 (limit: 2200)
    Memory: 3.1M
    CGroup: /system.slice/nagios4.service
    ├─2418 /usr/sbin/nagios4 -d /etc/nagios4/nagios.cfg
    ├─2419 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    ├─2420 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    ├─2421 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    ├─2422 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    ├─2423 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    ├─2424 /usr/sbin/nagios4 –worker /var/lib/nagios4/rw/nagios.qh
    └─2428 /usr/sbin/nagios4 -d /etc/nagios4/nagios.cfg

    Thanks for the help

    • RaspberryTips Post authorReply


      Do you have an error when you start the service?

      Or can you check the log file?
      I think it’s in /var/log/syslog

  7. G3n3r4l_Murloc Reply


    Thanks for the fast reply,
    I have find this in the log file regarding Nagios :
    Jul 29 21:19:09 raspberrypi nagios4[4410]: Starting nagios4 monitoring daemon: nagios4.
    Jul 29 21:19:09 raspberrypi nagios4: Nagios 4.3.4 starting… (PID=4440)
    Jul 29 21:19:09 raspberrypi nagios4: Local time is Mon Jul 29 21:19:09 CEST 2019
    Jul 29 21:19:09 raspberrypi nagios4: LOG VERSION: 2.0
    Jul 29 21:19:09 raspberrypi nagios4: qh: Socket ‘/var/lib/nagios4/rw/nagios.qh’ successfully initialized
    Jul 29 21:19:09 raspberrypi nagios4: qh: core query handler registered
    Jul 29 21:19:09 raspberrypi nagios4: nerd: Channel hostchecks registered successfully
    Jul 29 21:19:09 raspberrypi nagios4: nerd: Channel servicechecks registered successfully
    Jul 29 21:19:09 raspberrypi nagios4: nerd: Channel opathchecks registered successfully
    Jul 29 21:19:09 raspberrypi nagios4: nerd: Fully initialized and ready to rock!
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Successfully registered manager as @wproc with query handler
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4442;pid=4442
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4443;pid=4443
    Jul 29 21:19:09 raspberrypi systemd[1]: Started LSB: nagios host/service/network monitoring and management system.
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4446;pid=4446
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4441;pid=4441
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4444;pid=4444
    Jul 29 21:19:09 raspberrypi nagios4: wproc: Registry request: name=Core Worker 4445;pid=4445
    Jul 29 21:19:09 raspberrypi nagios4: Successfully launched command file worker with pid 4450

    I also tried this :
    sudo nagios4 restart
    output :
    Nagios Core 4.3.4
    Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 2017-08-24
    License: GPL

    Error: Cannot open main configuration file ‘/usr/local/nagios/etc/objects/restart

    But I think that’s normal, there is no “restart” file in this folder

    • RaspberryTips Post authorReply


      There is no error in your log file, so I don’t know what the problem could be

      Good commands to manage the nagios service are:

      • sudo service nagios start
      • sudo service nagios stop
      • sudo service nagios restart

      You can also try sudo journalctl -xe to see the last errors

  8. Zvonimir Reply

    Hello, I followed you tutorial and it is really good. Had some problems but figured it out. Can you help me with installing Nagios network analyzer on raspbian? Nagios server is already up and working. Can I manually put NAA or not?

Leave a Reply

Your email address will not be published. Required fields are marked *