# devops / monitoring / nagios

Continuous Monitoring with Nagios

Nagios is an industry-standard open-source tool used to continuously monitor network devices, applications, and servers. Its powerful core engine can scale to monitor thousands of hosts efficiently.

$ /usr/local/nagios/libexec/check_load
Targetweb-prod-01
MetricCPU Load Average
OutputOK - load average: 0.45, 0.50, 0.40
StatusHealthy
Active
Check Type
NRPE
Execution
# capabilities

What You Can Monitor

Nagios provides deep visibility into your infrastructure, alerting you the second a critical service fails or a server starts running out of resources.

targets

End-to-End Visibility

Server Resources: CPU load, memory utilization, disk space.
Network Services: HTTP, FTP, SMTP, SSH, Ping.
Infrastructure: Routers, switches, applications, databases, and system logs.

alerting

Fast Notifications

Sends alerts via email, SMS, or custom integrations immediately after detecting issues, minimizing downtime.

extensibility

Custom Plugins

Highly flexible architecture supports plugins written in bash, Python, PHP, or Perl to monitor absolutely anything.

# architecture

How Nagios Works

The Nagios ecosystem relies on a central server scheduling checks and distributed plugins executing the actual metric collection on remote machines.

Core Components

  • Nagios Server

    Installed on the main host, it runs the core monitoring engine, scheduling, and web interface.

  • NRPE Daemon

    Nagios Remote Plugin Executor: An agent installed on remote Linux servers that allows the central server to securely execute local plugins.

  • Plugins

    Compiled executables or scripts that do the actual work of collecting metrics (e.g., checking disk space).

  • Scheduler

    The internal clock of Nagios that determines when to execute plugins based on user-defined intervals.

# workflow

Checks & The Monitoring Flow

Active Checks

Nagios dictates the schedule. The central server initiates the check, connects to the remote service (often via NRPE), and pulls the status back.

Passive Checks

External applications or remote hosts initiate the process, pushing status information back to the Nagios server asynchronously. Great for firewall-restricted environments.

The Active Monitoring Workflow

  • 1. Schedule

    Nagios Scheduler triggers a check event based on time periods.

  • 2. Execute

    Nagios reaches out and executes the corresponding Plugin.

  • 3. Collect

    The Plugin interrogates the system and collects the raw metric data.

  • 4. Return

    Status code (OK, WARNING, CRITICAL, UNKNOWN) is returned to Nagios.

  • 5. Process & Alert

    Nagios processes the result and fires off notifications if an issue is detected.

# internals

Directories & Configuration

/usr/local/nagios/TREE
1
nagios/
├── bin       # Main Nagios daemon binary
├── etc       # All configuration files (.cfg)
├── libexec   # Plugins used for monitoring (CRITICAL)
├── sbin      # CGI executables for web interface
├── share     # Web interface HTML and PHP files
└── var       # Runtime data, status.dat, and logs
CRITICAL FOLDER

The libexec directory is where all the actual monitoring scripts live. If you download a custom plugin from the internet, you must place it here and make it executable.

Important File Purpose / Definition
nagios.cfg Main config file defining global settings and including other files.
resource.cfg Stores sensitive info securely, like database passwords (e.g., $USER1$).
commands.cfg Maps command names to actual plugin execution strings.
contacts.cfg Defines the users and email addresses that receive alert notifications.
templates.cfg Defines generic host/service templates to reduce code duplication.
timeperiods.cfg Defines valid monitoring hours (e.g., 24x7, or WorkHours only).
cgi.cfg Controls web interface access, permissions, and behavior.
.htpasswd Apache file that secures the Nagios web UI with login credentials.