Nagios plugin for Apache

Posted by Sam

I've been using Nagios for years and for monitoring it's been great. The biggest problem is that there has never been a decent graphing solution that wasn't a giant pain in the butt. Thankfully that's no longer the case. I recently stumbled across pnp and it's been perfect. Good enough in fact that I've stopped looking for a replacement.

Since Phusion will now compile on Solaris I've switched from LiteSpeed back to Apache. Since going back to Apache I decided to dust off an old Nagios script I had for monitoring Apache's processes. It's pretty basic but it works with pnp to graph how busy your Apache servers are. Here's the script.

#!/opt/csw/bin/python

import httplib,re,sys,getopt

#Return codes
OK      = 0
Warning = 1
Critical = 2
Unknown = 3

#Variables
hostname = ''
warningThreshold = -1
criticalThreshold = -1


def getUsers(hostname):
  con = httplib.HTTPConnection(hostname)
  con.request("GET", "/server-status")
  res = con.getresponse()
  results = res.read()
  con.close()

  match = re.search("\d+ requests currently", results)
  if match:
    newmatch = re.search("\d+", match.group())
    if newmatch:
      return int(newmatch.group())
    else:
      return -1
  else:
    return -1

def showUsage():
  print sys.argv[0]+' -h -H hostname -w warning -c critical'
  sys.exit()

#Get command line options
try:
  optlist, args = getopt.getopt(sys.argv[1:], '-h-H:-w:-c:')
except:
  showUsage()


for o, a in optlist:
  if o == '-h':
    showUsage()
    sys.exit()
  if o == '-H':
    hostname = a
  if o == '-c':
    criticalThreshold = int(a)
  if o == '-w':
    warningThreshold = int(a)

# Validate command line options
if criticalThreshold == -1:
  print 'critical threshold was not set'
  showUsage()
if warningThreshold == -1:
  print warningThreshold
  print 'warning threshold was not set'
  showUsage()
if hostname == '':
  print 'hostname was not set'
  showUsage()

try:
  currentUsers = getUsers(hostname)
except:
  print 'Unknown'
  sys.exit(Unknown)
if currentUsers >= criticalThreshold:
  print 'Critical: '+str(currentUsers)+' users|current_users='+str(currentUsers)
  sys.exit(Critical)
elif currentUsers >= warningThreshold:
  print 'Warning: '+str(currentUsers)+' users|current_users='+str(currentUsers)
  sys.exit(Warning)
elif currentUsers >= 0:
  print 'OK: '+str(currentUsers)+' users|current_users='+str(currentUsers)
  sys.exit(OK)
else:
  print 'Unknown'
  sys.exit(Unknown)

Tags: nagios apache

Installing Phusion Passenger on Solaris

Posted by Sam

I know there are other places on the web where you can piece this together but I thought I'd throw up how I got Phusion Passenger compiled on a Solaris 10 zone with Blastwave packages. Well technically the packages are from opencsw.com but they should behave exactly the same (for now). Also, as of the time of this writing the most recent version (2.0.6) didn't compile. I had to grab the trunk from GitHub.

bash-3.00# crle -l /lib:/usr/lib:/opt/csw/lib
bash-3.00# export PATH=/opt/csw/apache2/bin:/opt/csw/apache2/sbin:$PATH
bash-3.00# export APXS2=/opt/csw/apache2/sbin/apxs
bash-3.00# export APR_CONFIG=/opt/csw/apache2/bin/apr-1-config
bash-3.00# gem install passenger
bash-3.00# ./bin/passenger-install-apache2-module

The first line is not something I use regularly and you definitely want to use it with care. Basically it tells the system where to find libraries. Before I added this line Ruby Enterprise Edition and Phusion couldn't find their runtime libraries unless I set LD_LIBRARY_PATH. Relying on LD_LIBRARY_PATH isn't a good idea and didn't work for daemons so I used crle instead. You should run crle first to make sure you don't have other paths set before overriding it.

Once everything finishes you should have a working Passenger install. Note this has only been tested on Solaris 10 x86 update 6. Also, one machine had the gnu version of ld installed and it was causing a weird error. Once I removed SUNWtoo it compiled fine.

Tags: solaris rails passenger apache blastwave opencsw

Why is Apache SO annoying?

Posted by Sam

I guess I've been getting spoiled by LiteSpeed's excellent web server lately because after working with Apache for about an hour I'm thoroughly annoyed. Why do you need to tell Apache that you are going to use it for virtual hosting? Seriously? Every web server I've seen in the last seven or eight years has been configured for virtual hosting. Does Apache still need a directive for that? And why on earth does the entire web server fail to start when you forget to create a directory for the log files? At most I could see not starting that site. And that's at most. I didn't realize how annoying Apache is until I switched to something else. IIS is just as annoying, just in different ways. LiteSpeed on the other hand is outstanding. For those of you jumping through Mongrel and Apache hoops for your Rails deployments I strong recommend you look at LiteSpeed. It's much nicer and a LOT faster than Apache.

Tags: litespeed apache