Monitoring Apache Connections And Proceses With MRTG

David Horwitz 02 March, 2009 10:29 General, Sakai Permalink Trackbacks (0)

When running web based applications with Apache as a front end it is useful to monitor the number of connections on Apache and number of Apache processes. Under certain conditions Apache can spawn extra proccesses and many of theem indicated reduced QOS for your end users. They include:

  1. The back end aplication taking too long to process requests
  2. network related problems
  3. resource contention on the box hosting Apache.
Its pretty easy to monitor this using MRTG.  First a simple perl script:


#! /usr/bin/perl

use strict;

my $connections = `netstat -n | grep EST | grep "137.158.155.8:443 " | wc -l`;
my $processes = `ps ax | grep -c httpd`;

chomp($connections);
chomp($processes);

print $connections . "\n";
print $processes . "\n";

Edit the ip address to match your host. This will give you a count of connections and processes. Next the MRTG conf:

 

# Created by
# /usr/local/bin/cfgmaker public@localhost

### Global Config Options

#  for UNIX
WorkDir: /srv/www/vhosts/vula.uct.ac.za/mrtg/
IconDir: /mrtg/icons/

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, noinfo, nopercent, integer, gauge

EnableIPv6: no

### Interface 1 >> Descr: 'em0' | Name: '' | Ip: '137.158.128.44' | Eth: '' ###

MaxBytes[_]: 4061814272
ShortLegend[_]:  
YLegend[_]: https connections
AddHead[_]: <link href="/library/skin/default/tool.css" type="text/css" rel="stylesheet" media="all" />
PageFoot[_]: </div>
kilo[_]: 1024

Target[https-connections]: `/usr/local/sakaiscripts/https-connections.pl`
Title[https-connections]: HTTPS Connections
PageTop[https-connections]: <div class="portletBody"><H3>HTTPS Connections</H3>
LegendI[https-connections]: &nbsp;connections:
LegendO[https-connections]: &nbsp;httpd processes:
Legend1[https-connections]: HTTPS connections (5 min interval)
Legend2[https-connections]: httpd processes
Legend3[https-connections]: Maximal HTTPS connections (5 min interval)
Legend4[https-connections]: Maximal httpd processes
WithPeak[https-connections]: wmy

 

once again make sure the WorkDir and traget paths match the paths for your instalation. Workdir needs to be accesible via a browser (as MRTG will output to this directory). Now test your script by running:

env LANG=C /usr/bin/mrtg /usr/local/sakaiscripts/https-connections.cfg

Note MRTG will give warnings about the history files missing the first two times you run it. After that it should be silent. Finaly add the line to your crontab to run every 5 minute.

 

 


comments


Add comment

Topic

Text

Your name

Your email address (if any)

Your personal page (if any)

authimage


Powered by LifeType
© 2006 - Design by Omar Romero (all rights reserved)