Powered by Blogger.

MONITORING TOMCAT SESSIONS LOAD AND APACHE WORKERS STATUS WITH NAGIOS

Middleware Support Specialist, Alessandro Vaccarezza,offers a quick look at two useful monitoring processes that can be run from a windows client using a Virtual Machine.

Monitoring the middleware layer plays a vital role when providing managed services and hands-on support for customer application environments. Nagios is just one monitoring solution we use when setting up proactive performance monitoring and alerting - and is an essential tool, both for troubleshooting incidents, and when analysing data for longer-term improvements. 

We've touched on Nagios in previous blog posts, such as Alan Fryer's look at DevOps toolsets, and in this post, I'll look at a couple of simple checks that can be run from a Windows client using a Virtual Machine prior to deciding whether to create a command definition and a service:
Monitoring the status of and Apache http server
Monitoring the sessions load of an Apache Tomcat server

Whilst Nagios XI won’t install natively on a Windows Server, we can use a prepackaged VM and install it on VirtualBox - a general-purpose full virtualizer for x86 hardware. Note: If you're planning to run your Nagios checks from the VM permanently, then you might want to download the VirtualBox Extension Pack and the Guest Additions as well. You can find the download here: https://www.virtualbox.org/wiki/Downloads


Download Nagios XI, packaged as Open Virtualization Format, and install it on VirtualBox following the steps on this PDF. The instructions target VMware Workstation Player which is very similar to VirtualBox.

Once you followed the steps, you should have access to the Nagios XI filesystem on the VM and access to NXI web console.

The configuration we are going to monitor is running on AWS, Amazon Linux AMI 64 bit, and it contains an Apache 2.4.25 and an Apache Tomcat 7 instance.

The first plugin aims at monitoring Apache idle workers, through the mod_status module. 
Before we can use it, the mod_status module must be enabled. Open the Apache’s httpd.conf file (or apache2.conf if you're under Ubuntu): add the following section to the file, properly replacing the IP address with the one of your Windows machine, and restart Apache.ExtendedStatus on <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from IP.AD.DR.ESS </Location> 


To make sure the status module is enabled, visit: http://IP_ADDRESS_OF_THE_MACHINE_RUNNING_APACHE/server-status 
and you should see the following:


Download the plugin and store it on your local machine. 

Open Nagios XI web interface and navigate to Admin > System Extensions > Manage Plugins. Use the Browse and Upload Plugin buttons to upload the plugin. You should now see it listed:


The plugin syntax is as follows: check_apache2.py
[ -H hostname or IP address ] 
[ -P port ] [ -w warning ] [ -c critical ]
Establish a terminal session to your Nagios XI server as the root user and navigate to /usr/local/nagios/libexec/.

The plugin usage is as follows:

check_apache2.py [ -H hostname or IP address ] 
[ -P port ] 
[ -w warning ] [ -c critical ]

The above tells us we need to provide the following arguments:
-H = Address of Tomcat server
-P = Port the Tomcat server is listening on
-w = The warning threshold 
-c = The critical threshold 

Enter the following instruction:./check_apache2.py -H IP_ADDRESS_OF_THE_MACHINE_RUNNING_APACHE



As you can see from the screenshot the configuration we’re using is really minimal, 1 busy worker and 6 idle ones.

If you are getting the following message that means that the httpd.conf file was not edited correctly:

CRITICAL: Couldn't fetch the server's status page. Please check given hostname, port or Apache's configuration. We might not be allowed to access server-status due to your server's configuration.

The next plugin checks the active sessions on an Apache Tomcat instance, we are using Tomcat 7 for this example.

Before we can use it, there must be a valid user configured within Tomcat with the role of manager-script, we are going to use its credentials to run our check: if you have not such role assigned, navigate to tomcat-users.xml, add it and restart Tomcat.

Open the Nagios XI web interface and navigate to Admin > System Extensions > Manage Plugins. Use the Browse and Upload Plugin button to upload the check_tomcatSessions plugin.


Establish a terminal session to your Nagios XI server as the root user and navigate to
/usr/local/nagios/libexec/.

The plugin usage is as follows:

check_tomcatSessions [ -H hostname or IP address ] 
[ -P port ] [ -u username ] 
[ -p password ] [ -s session_name ] 
[ -w warning ] [ -c critical ]
[ -V tomcat_version ]

The above tells us we need to provide the following arguments:
-H = Address of Tomcat server
-P = Port the Tomcat server is listening on
-u = Username to access the Tomcat server
-p = Password for the username 
-s = The session name to check, if omitted (default) then the total number of sessions is calculated 
-w = The warning threshold 
-c = The critical threshold 
-V = The Tomcat version 

Enter the following instruction:./check_tomcatSessions -H IP_ADDRESS_OF_THE_MACHINE_RUNNING_TOMCAT -P 8080 -u admin -p adminadmin -s manager -w 10 -c 40 -V 7



The above tells us the manager session is in an OK state, because only one session is running at this
time.
Now that you have tested the check_tomcatSessions plugin and it is running successfully from the
command line and returning valid information, you can move on to integrating this check with Nagios XI.

This is done by:
Creating a command definition for the check_tomcatSessions plugin
Creating a Nagios XI host object for your Tomcat server
Creating a service that uses the newly created command
Conclusions

The Nagios XI plugin ecosystem is quite rich, but not when it comes to Apache or Tomcat, for which few interesting plugins are available - and most of them are out of date. Nevertheless, given the infinite potential of a smart solution such as Nagios XI, everyone could write their own script and metrics using Python or Bash, to interact with any server.
    Blogger Comment
    Facebook Comment