mrtg and apache

Yes, I’m a stats freak. So, here’s how you get mrtg to plot your Apache server activity. (Note, I’ve been told that mod_watch also does this, but I have not looked at it yet.)

Here’s /usr/local/bin/apache-stats :

# apache-stats 
use LWP::Simple;

my $stats=get("http://servername/server-status?auto");
$stats =~ s/.*BusyServers: (d+)//;
my $b = $1;
print "$bn";
$stats =~ s/.*IdleServers: (d+)//;
print $b + $1 . "n";
print "nn";

Note that in Apache 2.0, you want “BusyThreads” rather than “BusyServers”, and similarly for IdleThreads.

Then, in your mrtg.cfg,

Target[apache_child]: `/usr/local/bin/apache-stats`
MaxBytes[apache_child]: 100000
Options[apache_child]: growright,gauge,nopercent,dorelpercent
Title[apache_child]: Apache Statistics
PageTop[apache_child]: <h1>Active Apache child processes</h1>
XSize[apache_child]: 500
YSize[apache_child]: 200
WithPeak[apache_child]: dwmy
YLegend[apache_child]: No. of child processes
ShortLegend[apache_child]: processes
LegendI[apache_child]:  active:
LegendO[apache_child]:  total: 

Tweak as needed. That should get you started.