What Nagios does for network services
Nagios is an open-source monitoring system. Its job is to check whether the services on your network are working and to tell the right people when they are not. A service can be almost anything that answers a request: a web server on port 80, a mail server, a DNS resolver, or a router that replies to ping.
Nagios watches these services from the outside, or through a small agent on the machine, and records what it finds. It does not repair anything by itself. Its value lies in running checks on a fixed schedule, keeping an up-to-date view of every host and service, and raising alerts when something changes.
If you are new to this area, it helps to know where Nagios fits among the specific tools to monitor availability of network systems that administrators use. It is one of the older and most widely known options in that group.
How the Nagios core works
The central piece is the Nagios Core daemon. It runs on a monitoring server and handles a handful of jobs:
- It reads its configuration from plain text files.
- It schedules checks and runs them at the intervals you set.
- It records the result of each check and keeps the current state of every host and service.
- It decides when a state change deserves a notification, and who should receive it.
- It shows the status through a web interface.
Because everything is driven by configuration files, a Nagios setup is easy to keep in version control and copy to another server. The trade-off is that changes are made by editing text rather than by clicking.
Plugins do the actual checking
Nagios does not know how to test a web server or a disk by itself. The tests are carried out by plugins, which are separate programs that Nagios runs. The standard plugin collection covers common checks such as:
- ping, to see whether a host is reachable
- HTTP, to see whether a web server responds and with what status
- TCP ports, to see whether a port accepts connections
- SSH, to see whether the SSH service is up
- disk space and system load on the host
Other plugins are available from the community, and you can write your own in any language that can run as a program.
Each plugin reports its result with an exit code, which Nagios reads as a state:
| Exit code | State | Meaning |
|---|---|---|
| 0 | OK | The check passed |
| 1 | WARNING | Something needs attention soon |
| 2 | CRITICAL | The service is failing |
| 3 | UNKNOWN | The plugin could not determine the state |
Plugins also print a line of text, which appears in the web interface and in alerts. Many can add performance data after a pipe character, and add-ons can use that data to draw graphs.
Active and passive checks
Nagios supports two ways of getting results:
- Active checks are started by Nagios itself on a schedule. This is the usual method for confirming that a service answers.
- Passive checks are results that another system sends to Nagios. They suit cases where a job already runs elsewhere, such as a backup process that reports its own outcome, or where a check cannot be started from the server.
Passive results are usually submitted through the external command interface or through an add-on such as NSCA (Nagios Service Check Acceptor).
Monitoring remote hosts
Some checks run from the Nagios server over the network. Ping, HTTP, TCP and SNMP checks all work this way, since they talk to the target directly.
Other checks, such as disk usage or memory, have to run on the machine being monitored. For these, the usual approach is to install an agent such as NRPE (Nagios Remote Plugin Executor). The server asks the agent to run a named local check, and the agent sends the result back. NRPE listens on TCP port 5666 by default, so limit which addresses can reach it and enable its encryption options.
Alerts and notifications
When a service changes state, Nagios can notify the contacts you have defined. Notifications can go by email, to a pager or SMS gateway, or to a script you write. Three settings keep alerts useful:
- Time periods limit when checks and notifications apply, for example only during working hours.
- Escalation sends later notifications to a second contact if a problem continues.
- Notification options control which states and changes trigger an alert, so you are not flooded with repeats.
Good alert settings take some tuning. Start with a small set of critical services, then widen the list once you trust the alerts.
Defining what gets monitored
Nagios uses object definitions in its configuration files. The main types are:
- host, a machine or device
- service, a check attached to a host
- command, the plugin call that a check uses
- contact and contact group, the people who receive alerts
- time period, when checks and alerts are active
Templates keep files short by letting many objects share settings. A simple service definition looks like this:
define service {
use generic-service
host_name web01
service_description HTTP
check_command check_http
}
This tells Nagios to run the check_http command against the host web01, using the shared settings from the generic-service template.
Viewing status and history
The web interface lists hosts and services with their current states, the problems that need attention, and logs of past events. It is useful for a quick look during an incident.
Nagios Core focuses on current state and alerts. Graphs and long-term trends usually come from add-ons. PNP4Nagios is a common choice for graphing the performance data that plugins report. Some teams send results to other systems for dashboards and reporting instead.
Strengths and limits
Nagios has several strengths:
- a large library of plugins and add-ons, built up over many years
- low overhead for simple checks
- flexibility, since almost any service that can be tested from a command line can be monitored
- wide documentation and a large community of people who have run it
It also has limits to plan for:
- large sets of configuration files become hard to manage by hand
- graphs and trend reports need extra add-ons
- device discovery is mostly manual unless you add tools for it
- the built-in web interface looks dated to many users
Many teams compare Nagios with Zabbix, Icinga and Prometheus before choosing. Each differs in discovery, storage and graphing.
How to get started
- Install Nagios Core on a Linux server, along with the standard plugins. You can use a package from your distribution or build from source.
- Define one host and one simple service, such as a ping or HTTP check.
- Verify the configuration before you restart. Nagios has a verify option that reads the main configuration file and reports errors. Run it before every restart.
- Add a contact and test that the notification arrives.
- Add services gradually, and tune notifications as you learn what matters.
Starting small makes problems easier to find. Once the first checks run reliably, most of the remaining work is repeating the same pattern for each new service.