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/

Edit that file so that it looks like this:


open(PROCESS, "ps ax | grep httpd | grep -c : |");
$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/

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.


  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?

  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.

  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 ...



Comments for posts over 14 days are moderated