Back to the main page
Install and configure Nagios and Pnp4nagios on Oracle Linux 6
Installation
- Have the rpmforge.repo as yum repository
- Use "yum install nagios" to install Nagios (version 3.2.3) and all dependencies
- It's nice, not must to have graphing tool, there are many available ones like NagiosGrapher, pnp4nagios, etc.
- Let's install pnp4nagios, first download source from http://sourceforge.net/projects/pnp4nagios/
- I like doing installation from rpm, so let's build rpm for pnp4nagios
- Place tar.gz file in /usr/src/redhat/SOURCES/ (or /root/rpmbuild/SOURCES/ )
- Get pnp4nagios.spec file from tar.gz and place it in /usr/src/redhat/SPECS/ (or /root/rpmbuild/SPECS/ )
- Verify dependencies with : rpmbuild -bl pnp4nagios.spec
- Install needed s/w using yum
- Another verification can be : rpmbuild -ba --nobuild pnp4nagios.spec
- If all is well, build rpm with: rpmbuild -ba pnp4nagios.spec
- RPM will most likely be written in /usr/src/redhat/RPMS/i386/ (or /root/rpmbuild/RPMS/[x86_64|noarch]/ for example)
- Finally run: yum localinstall pnp4nagios-0.6.25-1.i386.rpm
Configuration
Apache
Apache (ver.2) main index page is /var/www/html/index.html
Go to http://<your_hostname> to see it.
Main Apache configuration file is /etc/httpd/conf
It has directive "Include conf.d/*.conf" which means that directory /etc/httpd/conf.d/ contains web configs for nagios, mrtg, pnp4nagios.
MRTG
MRTG is used to graph Nagios performance. The config file to check Nagios performance is /etc/mrtg/mrtg.cfg
Checks run every 5 min via cronjob, see the file /etc/crontab
It has the line:
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
To see graphs, visit URL and click on links: http://<hostname>/mrtg/nagios-stats.html
Nagios
The directory /etc/nagios/ is where Nagios is configured. Main configuration file is nagios.cfg
Use resource.cfg to define $USERx$ macros.
After doing any change to Nagios configuration, including adding/removing host/service, first check configuration before commit change. Warnings can be ignored, but errors must be fixed (do not restart/reload nagios with errors).
[root@hostname]# service nagios configtest
Checking config for nagios: [ OK ]
[root@hostname]# service nagios reload
nagios (pid 888) is running...
Reloading nagios: [ OK ]
|
Manual check of Nagios configuration can be done with command: nagios -v /etc/nagios/nagios.cfg
Pnp4nagios
This is Nagios graphing tool. There are several modes to process performance data, this is example with Bulk Mode with NPCD.
Bulk mode with NPCD reduces the load on the server because data collector process_perfdata.pl is not invoked for every host/service check. Nagios writes data to a temporary file in defined format. The file is processed by process_perfdata.pl at certain intervals, this is done by Nagios engine.
The NPCD daemon (Nagios Performance C Daemon) will monitor the directory for new files and will pass the names to /usr/libexec/process_perfdata.pl. Processing of performance data is decoupled completely from nagios. NPCD itself is able to start multiple thread for processing the data.
Configuration (example, may be different for others):
- Configuration directory: /etc/pnp4nagios/
- NPCD (Nagios-Perfdata-C-Daemon) config file : /etc/pnp4nagios/npcd.cfg
- Enable performance data in /etc/nagios/nagios.cfg
-
process_performance_data=1
host_perfdata_file=/var/log/nagios/host-perfdata # this temp file contains performance data
service_perfdata_file=/var/log/nagios/service-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
host_perfdata_file_mode=a
service_perfdata_file_mode=a # append data to a file
host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15 # 15 sec interval
host_perfdata_file_processing_command=process-host-perfdata-file # command called during interval
service_perfdata_file_processing_command=process-service-perfdata-file
- Command are defined in /etc/nagios/objects/commands.cfg
-
define command{
command_name process-service-perfdata-file
command_line /bin/mv /var/log/nagios/service-perfdata /var/spool/pnp4nagios/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /var/log/nagios/host-perfdata /var/spool/pnp4nagios/host-perfdata.$TIMET$
}
- Location of RRD and xml (metadata) files
-
/var/lib/pnp4nagios/
/var/lib/pnp4nagios/ is symbolic link to /etc/nagios/pnp4nagios/perfdata (just in case data outgrow /var )
How it works:
- Nagios runs a plugin
- Returned performance data is stored in the spool file
- Spool file is moved to spool directory (for example /var/spool/pnp4nagios/)
- Service npcd (Nagios-Perfdata-C-Daemon) scans spool directory (default every 15 sec)
- Service npcd runs process_perfdata.pl ( example /usr/libexec/pnp4nagios/process_perfdata.pl )
- RRD database is updated
- XML meta data file is updated
[root@hostname]# chkconfig --list npcd
npcd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@hostname]# service npcd status
npcd (pid 919) is running...
[root@hostname]# ps -ef | grep npcd
nagios 919 1 0 09:53 ? 00:00:00 /usr/bin/npcd -d -f /etc/pnp4nagios/npcd.cfg
|
NPCD log file is /var/log/nagios/npcd.log
The pnp4nagios uses templates to create graphs, default ones (extension .php) are located in directory /usr/share/pnp4nagios/templates.dist/
Sometimes when you create new custom Nagios plugin, it may be problem to get desired graph.
In this case you can copy default template to directory /usr/share/pnp4nagios/templates and name template as service name.
Example: There is plugin to check usage of disk/share on ZFS storage, so default graph for disk check (/usr/share/pnp4nagios/templates.dist/check_disk.php) is copied to /usr/share/pnp4nagios/templates/check_zfsappliance_share_usage.php
And to verify pnp4nagios configuration, use the perl scrpt verify_pnp_config.
The example: perl verify_pnp_config -m bulk+npcd -c /etc/nagios/nagios.cfg -p /etc/pnp4nagios
Back to the main page