Friday, June 3, 2011

PNP4Nagios with CentOS

PNP4Nagios with CentOS:

PNP is an addon to Nagios which analyzes performance data provided by plugins and stores them automatically into RRD-databases

Prerequisites

RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings.
Our CentOS server needed a few devel libraries installed for RRDtool:

yum -y install cairo-devel glib2-devel pango-devel

Download the latest source for RRDtool

mkdir ~/downloads && cd ~/downloads
wget
http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz
tar zxf rrdtool-1.4.3.tar.gz
cd rrdtool-1.4.3

Configure it with a few adjustments for our setup:

./configure --prefix=/usr/local/rrdtool

If everything is ok, then build and install it

make
make install


Zlib support for PHP -
--with-zlib

Installation
Download the
latest version of PNP4Nagios:

cd /extra/src
wget
http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.3.tar.gz/download
tar
zxf pnp4nagios-0.6.3.tar.gz
cd pnp4nagios-0.6.3

Configure it:

./configure \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool \
--with-httpd-conf=/usr/local/apache2/conf/extra \
--with-perl_lib_path=/usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi

Then build and install:

make all
make install

Copy the sample config files:

make install-config

Add pnp4nagios to your Apache configuration:

Install the Apache config file into /etc/httpd/conf.d/pnp4nagios.conf:

make install-webconf

Then edit /etc/httpd/conf/httpd.conf and add a line to load the PNP4Nagios conf file:

Include conf.d/pnp4nagios.conf

or can add the contents of httpd.conf to your Nagios VirtualHost directive:

Alias /pnp4nagios "/usr/local/pnp4nagios/share"


AllowOverride None
Order allow,deny
Allow from all
#
# Use the same value as defined in nagios.conf
#
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

# Turn on URL rewriting
RewriteEngine On
Options FollowSymLinks
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

- It might show error related to php-5.2, if it shows such issue add CentOS-Test repository and add following configuration as:

vi /etc/yum.repos.d/CentOS-Test-repo

[CentOS-testing]

name=CentOS-5 Testing

baseurl=http://dev.centos.org/centos/5/testing/$basearch/

enabled=1

gpgcheck=1

gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

update php:

yum update php


Restart httpd service:

service httpd restart


Access the PNP4Nagios Environment Tests by going to http://localhost/pnp4nagios. If it passes all the tests, remove the install.php file:

mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/old.install.php

NPCD Daemon

Copy the sample NPCD config file:

cp /usr/local/pnp4nagios/etc/npcd.cfg-sample /usr/local/pnp4nagios/etc/npcd.cfg

Data Collection :
Nagios needs to be
configured to trigger the data collector by editing /usr/local/nagios/etc/nagios.cfg and editing/uncommenting some lines:

process_performance_data=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata

Edit /usr/local/nagios/etc/objects/commands.cfg and remove the existing process-service-perfdata and process-host-perfdatacommands. Then add the new PNP4Nagios commands for service and host performance data logging:

define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

Nagios Web Front-End Integration :
In order to easily view the graphs from your Nagios server, we can take advantage of Nagios' external URL features in extended info configs. There are two ways of doing it - regular links or Javascript pop-ups:

Regular Links
Edit /usr/local/nagios/etc/objects/templates.cfg and add:

# PNP4Nagios host/service definitions
define host {
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}

OR

Javascript pop-ups :
Copy
status-header.ssi to your Nagios web files:

cp /downloads/pnp4nagios-0.6.3/contrib/ssi/status-header.ssi \
/usr/local/nagios/share/ssi/

Edit /usr/local/nagios/etc/objects/templates.cfg and add:

define host {
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}

To use them, add them to your host/service definitions with something similiar to:

define host{
use linux-server,host-pnp ; Name of host templates to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}

define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

Wednesday, June 1, 2011

SWAP Memory (Creating Swap file)

What is swap?

Swap space is an area on disk that temporarily holds a process memory image. When physical memory demand is sufficiently low, process memory images are brought back into physical memory from the swap area on disk. Having sufficient swap space enables the system to keep some physical memory free at all times.

There are three types of swap: device swap, file system swap and pseudo swap. Device swap is a separate partition allocated when the disk is configured. File system swap allows you to use the existing file system to allocate swap space. Pseudo swap is allocated from system memory on some systems.

How can I create swap on these machines?

Though we cannot create device swap, we can still create create file system swap. Steps are given below to create swap file:log-in as root and check your existing mounted partitions to create swap file using disk usage utility :

[root@shah-lp ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 9.9G 7.8G 1.6G 84% /

none 7.6G 0 7.6G 0% /dev/shm

/dev/sdb1 414G 32G 362G 8% /share

As we can see above /dev/sdb1 is mounted at /share and it got enough space to create swap file.

Assume my machine got 4GB physical RAM & 2GB of SWAP. Now we are looking to increase it to 8GB, 6GB more. follow below steps:

[root@shah-lp ~]# dd if=/dev/zero of=/share/swapfile bs=1G count=5

5+0 records in

5+0 records out

5368709120 bytes (5.4 GB) copied, 64.3235 seconds, 83.5 MB/s

[root@shah-lp ~]# mkswap /share/swapfile

[root@shah-lp ~]# swapon /share/swapfile

[root@shah-lp ~]# echo " /share/swapfile swap swap defaults 0 0" >> /etc/fstab

[root@shah-lp ~]# mount -a

To confirm run :

[root@shah-lp ~]# free -m

total used free shared buffers cached

Mem: 15367 11428 3938 0 53 10378

-/+ buffers/cache: 996 14370

Swap: 23551 0 23551

[root@shah-lp ~]# swapon -s

total used free shared buffers cached

Mem: 15367 11428 3938 0 53 10378

-/+ buffers/cache: 996 14370

Swap: 23551 0 23551