Monitoring Guide

    Self-Hosted Nagios Core

    Deploy Nagios Core, the industry-standard open source monitoring system, on RamNode VPS. Monitor servers, networks, and applications with powerful alerting.

    Ubuntu 22.04 / Debian 12
    Nagios 4.5+
    ⏱️ 30-45 minutes

    Why Nagios Core?

    Nagios Core is an open-source monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

    Monitor servers, networks, and applications
    Flexible alerting and escalation policies
    Extensible with thousands of plugins
    Web-based dashboard interface

    Prerequisites

    Requirements

    • • Ubuntu 22.04 or Debian 12
    • • Root or sudo access
    • • Minimum 1 GB RAM
    • • 20 GB disk space

    Optional

    • • Domain name for web access
    • • SSL certificate
    • • Mail server for notifications
    • • Additional hosts to monitor
    1

    Update Your System

    Start by ensuring your system is up to date:

    System Update
    sudo apt update && sudo apt upgrade -y

    Install Dependencies

    1

    Install Required Packages

    Install Apache, PHP, and build tools:

    Install Dependencies
    sudo apt install -y apache2 php libapache2-mod-php php-gd \
        wget unzip curl openssl libssl-dev build-essential \
        libgd-dev libperl-dev daemon autoconf gcc make
    2

    Create Nagios User and Group

    Create dedicated user and group for Nagios:

    Create User
    sudo useradd -m -s /bin/bash nagios
    sudo groupadd nagcmd
    sudo usermod -aG nagcmd nagios
    sudo usermod -aG nagcmd www-data

    Install Nagios Core

    1

    Download Nagios Core

    Download the latest Nagios Core release:

    Download Nagios
    cd /tmp
    NAGIOS_VER="4.5.2"
    wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-${NAGIOS_VER}/nagios-${NAGIOS_VER}.tar.gz
    tar -xzf nagios-${NAGIOS_VER}.tar.gz
    cd nagios-${NAGIOS_VER}
    2

    Compile and Install

    Compile and install Nagios:

    Build Nagios
    ./configure --with-httpd-conf=/etc/apache2/sites-enabled \
        --with-command-group=nagcmd
    make all
    sudo make install
    sudo make install-init
    sudo make install-commandmode
    sudo make install-config
    sudo make install-webconf
    3

    Configure Apache

    Enable required Apache modules and create admin user:

    Apache Setup
    # Enable required modules
    sudo a2enmod rewrite cgi
    
    # Create Nagios admin user for web interface
    sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
    
    # You'll be prompted to enter and confirm a password
    # Save this password securely!
    
    # Restart Apache
    sudo systemctl restart apache2

    Install Nagios Plugins

    1

    Download and Install Plugins

    Install the official Nagios plugins:

    Install Plugins
    cd /tmp
    PLUGINS_VER="2.4.10"
    wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-${PLUGINS_VER}/nagios-plugins-${PLUGINS_VER}.tar.gz
    tar -xzf nagios-plugins-${PLUGINS_VER}.tar.gz
    cd nagios-plugins-${PLUGINS_VER}
    
    # Compile and install
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    make
    sudo make install
    2

    Install Memory Check Plugin

    Install a custom memory monitoring plugin:

    Memory Plugin
    cd /usr/local/nagios/libexec
    sudo wget -O check_mem https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
    sudo chmod +x check_mem
    sudo chown nagios:nagios check_mem
    
    # Verify it works
    /usr/local/nagios/libexec/check_mem -f -w 80 -c 90
    3

    Start Nagios

    Verify configuration and start Nagios:

    Start Nagios
    # Verify configuration syntax
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
    # Enable and start Nagios service
    sudo systemctl enable nagios
    sudo systemctl start nagios
    
    # Check status
    sudo systemctl status nagios

    Command Definitions

    1

    Define Check Commands

    Edit the commands configuration:

    Edit Commands
    sudo nano /usr/local/nagios/etc/objects/commands.cfg
    commands.cfg
    # Memory check command
    define command {
        command_name    check_local_mem
        command_line    $USER1$/check_mem -f -w $ARG1$ -c $ARG2$
    }
    
    # Disk check command
    define command {
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
    }
    
    # Load check command
    define command {
        command_name    check_local_load
        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
    }

    Monitoring Configuration

    1

    Create VPS Configuration

    Create a monitoring configuration for your VPS:

    Create Config File
    sudo nano /usr/local/nagios/etc/objects/ramnode-vps.cfg
    ramnode-vps.cfg
    # Host definition
    define host {
        use                     linux-server
        host_name               ramnode-vps
        alias                   RamNode VPS Server
        address                 127.0.0.1
        max_check_attempts      5
        check_period            24x7
        notification_interval   30
        notification_period     24x7
    }
    
    # PING check
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%
    }
    
    # Root partition disk space
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     Disk Space - Root
        check_command           check_local_disk!20%!10%!/
    }
    
    # Memory usage
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     Memory Usage
        check_command           check_local_mem!80!90
    }
    
    # System load
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     System Load
        check_command           check_local_load!5.0,4.0,3.0!10.0,8.0,6.0
    }
    
    # Current users
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     Current Users
        check_command           check_local_users!20!50
    }
    
    # Total processes
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     Total Processes
        check_command           check_local_procs!250!400!RSZDT
    }
    
    # SSH service
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     SSH
        check_command           check_ssh
    }
    
    # HTTP service
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     HTTP
        check_command           check_http
    }
    
    # Swap usage
    define service {
        use                     local-service
        host_name               ramnode-vps
        service_description     Swap Usage
        check_command           check_local_swap!20%!10%
    }
    2

    Include Configuration

    Add the new config to Nagios:

    Edit nagios.cfg
    sudo nano /usr/local/nagios/etc/nagios.cfg
    
    # Add this line:
    cfg_file=/usr/local/nagios/etc/objects/ramnode-vps.cfg
    Validate and Restart
    # Verify configuration
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
    # Restart Nagios
    sudo systemctl restart nagios

    Threshold Tuning

    Recommended Thresholds by VPS Size

    VPS SizeLoad WarningLoad CriticalMem WarnMem Crit
    1 vCPU1.5,1.2,1.03.0,2.5,2.08090
    2 vCPU3.0,2.5,2.06.0,5.0,4.08090
    4 vCPU6.0,5.0,4.012.0,10.0,8.08595
    8 vCPU12.0,10.0,8.024.0,20.0,16.08595

    Load values are: 1-minute, 5-minute, 15-minute averages.

    Security

    1

    Enable HTTPS with Let's Encrypt

    Secure your Nagios installation with SSL:

    Install Certbot
    sudo apt install -y certbot python3-certbot-apache
    sudo certbot --apache -d nagios.yourdomain.com
    2

    Restrict Access by IP

    Limit access to trusted IPs:

    Edit Apache Config
    sudo nano /etc/apache2/sites-enabled/nagios.conf
    IP Restrictions
    <Directory "/usr/local/nagios/sbin">
        Options ExecCGI
        AllowOverride None
        <RequireAll>
            Require all granted
            Require ip 192.168.1.0/24
            Require ip your.public.ip.address
        </RequireAll>
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /usr/local/nagios/etc/htpasswd.users
        Require valid-user
    </Directory>
    Restart Apache
    sudo systemctl restart apache2
    3

    Configure Firewall

    Open required ports:

    UFW Rules
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw enable

    Email Notifications

    1

    Install Mail Utilities

    Install mail tools for notifications:

    Install Mail
    sudo apt install -y mailutils postfix
    
    # During Postfix installation:
    # - Select "Internet Site"
    # - Enter your server's hostname
    2

    Configure Contacts

    Update the Nagios admin contact:

    Edit Contacts
    sudo nano /usr/local/nagios/etc/objects/contacts.cfg
    contacts.cfg
    define contact {
        contact_name    nagiosadmin
        use             generic-contact
        alias           Nagios Admin
        email           your-email@domain.com
    }
    Restart Nagios
    sudo systemctl restart nagios

    Testing

    1

    Verify Services

    Check that all services are running:

    Check Status
    sudo systemctl status nagios
    sudo systemctl status apache2
    2

    Test Plugins Manually

    Test each plugin from the command line:

    Plugin Tests
    # Test disk check
    /usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
    
    # Test memory check
    /usr/local/nagios/libexec/check_mem -f -w 80 -c 90
    
    # Test load check
    /usr/local/nagios/libexec/check_load -w 5.0,4.0,3.0 -c 10.0,8.0,6.0
    
    # Test swap check
    /usr/local/nagios/libexec/check_swap -w 20% -c 10%
    3

    Access Web Interface

    Navigate to the Nagios dashboard:

    Web URL
    http://your-vps-ip/nagios

    Log in with the credentials you created earlier. You should see your host and all configured services.

    Troubleshooting

    1

    Common Issues

    Nagios won't start

    Debug
    sudo journalctl -u nagios -f
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Permission denied errors

    Fix Permissions
    sudo chown -R nagios:nagios /usr/local/nagios
    sudo chmod -R 755 /usr/local/nagios/libexec

    Web interface shows "Forbidden"

    Enable CGI
    sudo a2enmod cgi
    sudo systemctl restart apache2

    Plugins returning unknown status

    Check Plugins
    # Check plugin permissions
    ls -la /usr/local/nagios/libexec/
    
    # Test as nagios user
    sudo -u nagios /usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /

    Next Steps

    Configure NRPE for remote host monitoring
    Integrate with Slack or PagerDuty
    Add custom plugins from Nagios Exchange
    Set up event handlers for auto-remediation