Showing posts with label load monitoring. Show all posts
Showing posts with label load monitoring. Show all posts

Monday, August 29, 2011

How To Install Nagios NRPE Plugin

Concepts of Installation :

1. Download the source file for Nagios plugin + nrpe plugin on host and client.
2. Install the source files.
4. Add client to the host.
3. Config the sensor on host and client.

1. Installation on Client

1.1 Nagios Plugin

Download the source code tarball of the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions).

At the time of writing, the latest stable version of the Nagios plugins was 1.4.6.

wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.6.tar.gz

Extract the Nagios plugins source code tarball.

tar xzf nagios-plugins-1.4.6.tar.gz

cd nagios-plugins-1.4.6

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install


The permissions on the plugin directory and the plugins will need to be fixed at this point, so run the following commands.

chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec


1.2 NRPE Plugin

Download the source code tarball of the NRPE addon (visit http://www.nagios.org/download/ for links to the latest versions).

** At the time of writing, the latest version of NRPE was 2.8.

wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz

Extract the NRPE source code tarball.

tar xzf nrpe-2.8.tar.gz

cd nrpe-2.8

Compile the NRPE addon.

./configure
make all


** Install the NRPE plugin (for testing), daemon, and sample daemon config file.

make install-plugin
make install-daemon
make install-daemon-config

Install the NRPE daemon as a service under xinetd.

make install-xinetd

Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.

** only_from = 127.0.0.1

Add the following entry for the NRPE daemon to the /etc/services file.

nrpe 5666/tcp # NRPE

Restart the xinetd service.

service xinetd restart

Test the NRPE daemon locally :

** Its time to see if things are working properly...
** Make sure the nrpe daemon is running under xinetd.

netstat -at | grep nrpe

The output out this command should show something like this:

tcp 0 0 *:nrpe *:* LISTEN

** If it does, great! If it doesn't, make sure of the following:

- You added the nrpe entry to your /etc/services file
- The only_from directive in the /etc/xinetd.d/nrpe file contains an entry for "127.0.0.1"
- xinetd is installed and started
- Check the system log files for references about xinetd or nrpe and fix any problems that are reported

** Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that was installed for testing purposes.

/usr/local/nagios/libexec/check_nrpe -H localhost

** You should get a string back that tells you what version of NRPE is installed, like this:

NRPE v2.8

Open firewall rules :

Make sure that the local firewall on the machine will allow the NRPE daemon to be accessed from remote servers.

To do this, run the following iptables command :

** Note that the RH-Firewall-1-INPUT chain name is Fedora specific, so it will be different on other Linux distributions.

iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT

Save the new iptables rule so it will survive machine reboots.

service iptables save


Customize NRPE Plugin :

vi /usr/local/nagios/etc/nrpe.cfg

The commands should be synchronized with Nagios host configuration for client.


Wednesday, June 1, 2011

Load Monitoring Script For Linux #1

#!/bin/bash
#
# Script to notify admin user if Linux,FreeBSD load crossed certain limit
# It will send an email notification to admin.
#
# Copyright 2005 (c) nixCraft project
# This is free script under GNU GPL version 2.0 or above.
# Support/FeedBack/comment : http://cyberciti.biz/fb/
# Tested os:
# * RedHat Linux
# * Debain Linux
# * FreeBSD
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------

# Set up limit below
NOTIFY="4.0"

# admin user email id
EMAIL="yourmail@mail.com"

# Subject for email
SUBJECT="Alert $(hostname) Load Average Exceeded The Limit"

# -----------------------------------------------------------------

# Os Specifc tweaks do not change anything below ;)
OS="$(uname)"
TRUE="1"
if [ "$OS" == "FreeBSD" ]; then
TEMPFILE="$(mktemp /tmp/$(basename $0).tmp.XXX)"
FTEXT='load averages:'
elif [ "$OS" == "Linux" ]; then
TEMPFILE="$(mktemp)"
FTEXT='load average:'
fi

# get first 5 min load
F5M="$(uptime | awk -F "$FTEXT" '{ print $2 }' | cut -d, -f1)"
# 10 min
F10M="$(uptime | awk -F "$FTEXT" '{ print $2 }' | cut -d, -f2)"
# 15 min
F15M="$(uptime | awk -F "$FTEXT" '{ print $2 }' | cut -d, -f3)"

#Save the current running processes in a file
/bin/ps -auxf >> /root/ps_output

# mail message
# keep it short coz we may send it to page or as an short message (SMS)
echo "Load average Crossed allowed limit $NOTIFY." >> $TEMPFILE
echo "Hostname: $(hostname)" >> $TEMPFILE
echo "Local Date & Time : $(date)" >> $TEMPFILE
echo "Load Average :" >> $TEMPFILE
echo -e "\n" >> $TEMPFILE
echo "$(top -n 1 -b|head -20)" >> $TEMPFILE

# Look if it crossed limit
# compare it with last 15 min load average
RESULT=$(echo "$F15M > $NOTIFY" | bc)

# if so send an email
if [ "$RESULT" == "$TRUE" ]; then
mail -s "$SUBJECT" "$EMAIL" < $TEMPFILE
fi

# remove file
rm -f $TEMPFILE