Wednesday, January 21, 2009

Monitoring Apache Processes with Cacti

I've been setting up Cacti at work to monitor our servers. Last night it occured to me that it might be useful to monitor Apache processes on our web servers. Cacti already has a graph built in for monitoring processes in general, but I just wanted those that matched "httpd". It was a simple thing that I wanted, but setting it up proved to be non-trivial, so I thought I'd share how I set it up. Keep in mind that this is on a RHEL5.2 box. Your distribution may vary.

First of all, you need a script to gather the information. You already have one mostly built, so use it as a template:

cd /var/lib/cacti/scripts/
cp unix_processes.pl unix_apache_processes.pl

Edit that file so that it looks like this:

#!/usr/bin/perl

open(PROCESS, "ps ax | grep httpd | grep -c : |");
$output = ;
close(PROCESS);
chomp($output);
print $output;

Now you need to set up Cacti to use that script. Go into the Console tab in Cacti and click on "Data Input Methods". Click "Add", and use the following values:

Name: Unix - Get Apache Processes
Input Type: Script/Command
Input String: perl /scripts/unix_apache_processes.pl

Save it, then go back in and click on "Add" for "Output Fields". Use the following values:

Field [Output]: proc
Friendly Name: Number of Apache Processes
Update RRD File: (checked)

Go ahead and save it. Now go into "Graph Templates" and find the "Unix - Processes" template. Put a check next to it, go find the drop-down box next to "Choose an action", set it to "Duplicate" and click "go". Change the title to "Unix - Apache Processes" and save it.

Go back into "Graph Templates" and click on the "Unix - Apache Processes" template that you just created. Find everything that says "Processes" and change it to say "Apache Processes", then save it.

Go into "Data Templates" and find "Unix Processes". Duplicate it like you did with the Graph Template, calling the new template "Apache Processes". Then go back into it and change the "Data Input Method" drop-down to "Unix - Get Apache Processes".

Go back into "Graph Templates", then "Unix - Apache Processes" again and click on "Item # 1". Change the "Data Source" drop-down to "Apache Processes - (proc)" and hit "save". Do the same for "Item # 2", "Item # 3" and "Item # 4".

Now when you go into the "Devices" menu and click on one of your web servers, you should see "Unix - Apache Processes" show up on the drop-down box for "Associated Graph Templates". Go ahead and add it, then go up to the top of the device page and click "Create Graphs for this Host". Put a check next to "Unix - Apache Processes" and click "Create".

Setting up this graph may be pretty straight-forward for the average Cacti user, but there are a lot of steps, and it helps to do them in the right order. This walkthrough should give you a good start for adding more complex graphs to Cacti when you need to.

3 comments:

  1. thank for helpful how-to.
    But, this method cannot monitoring apache process on another sever(cacti device, SNMP host).
    Is there anyway to do that?

    ReplyDelete
  2. t a e: I have seen a script laying around that supports running tests via SSH. If you're willing to use a password-less key, that would probably be worth taking a look at.

    ReplyDelete
  3. Hi.

    You can solve this with user added MIBs on snmp client side. As a result of querying user added MIB this kind of script which output will cacti use for populating it's rrd files ...

    epohl

    ReplyDelete

Comments for posts over 14 days are moderated

Note: Only a member of this blog may post a comment.