| 1 |
#!/usr/bin/perl |
|---|
| 2 |
# |
|---|
| 3 |
# Plugin to monitor the number of apache-processes running on the |
|---|
| 4 |
# machine, and (in addition to a simple process count), separate then |
|---|
| 5 |
# into "busy" or "idle" servers. |
|---|
| 6 |
# |
|---|
| 7 |
# Requirements: |
|---|
| 8 |
# - Needs access to http://localhost/server-status?auto (or modify the |
|---|
| 9 |
# address for another host). See your apache documentation on how to |
|---|
| 10 |
# set up this url in your httpd.conf. |
|---|
| 11 |
# |
|---|
| 12 |
# Tip: To see if it's already set up correctly, just run this plugin |
|---|
| 13 |
# with the parameter "autoconf". If you get a "yes", everything should |
|---|
| 14 |
# work like a charm already. |
|---|
| 15 |
# |
|---|
| 16 |
# Parameters supported: |
|---|
| 17 |
# |
|---|
| 18 |
# config |
|---|
| 19 |
# autoconf |
|---|
| 20 |
# |
|---|
| 21 |
# Configurable variables |
|---|
| 22 |
# |
|---|
| 23 |
# urls - Override default status-url (SSL) |
|---|
| 24 |
# ports - HTTPS ports numbers (SSL) |
|---|
| 25 |
# |
|---|
| 26 |
# $Log$ |
|---|
| 27 |
# Revision 1.8 2006/03/07 20:30:00 fra519 |
|---|
| 28 |
# modified for Apache SSL Server. |
|---|
| 29 |
# |
|---|
| 30 |
# Revision 1.7.2.1 2005/02/24 17:51:08 jimmyo |
|---|
| 31 |
# modified graph_args of generic/apache_processes, to work around an rrdtool bug (Deb#296528). |
|---|
| 32 |
# |
|---|
| 33 |
# Revision 1.7 2004/05/20 13:57:11 jimmyo |
|---|
| 34 |
# Set categories to some of the plugins. |
|---|
| 35 |
# |
|---|
| 36 |
# Revision 1.6 2004/05/14 21:16:46 jimmyo |
|---|
| 37 |
# "Upped" som plugins from contrib/manual to auto. |
|---|
| 38 |
# |
|---|
| 39 |
# Revision 1.5 2004/04/27 08:46:57 jimmyo |
|---|
| 40 |
# Fixed broken autoconf in apache-* plugins (Deb#236144). |
|---|
| 41 |
# |
|---|
| 42 |
# Revision 1.4 2004/02/03 17:17:25 jimmyo |
|---|
| 43 |
# Generic/apache-plugins have been modified to properly to report the correct autoconf value. Also, bugfixes in _processes and _volume. |
|---|
| 44 |
# |
|---|
| 45 |
# Revision 1.3 2004/01/29 18:47:30 jimmyo |
|---|
| 46 |
# Made plugins apache_* compatible with older versions of LWP::UserAgent (SF#881411). |
|---|
| 47 |
# |
|---|
| 48 |
# Revision 1.2 2004/01/29 18:26:12 jimmyo |
|---|
| 49 |
# Bugfix, apache_processes now takes port numbers into account. (SF#882263) |
|---|
| 50 |
# |
|---|
| 51 |
# Revision 1.1 2004/01/02 18:50:00 jimmyo |
|---|
| 52 |
# Renamed occurrances of lrrd -> munin |
|---|
| 53 |
# |
|---|
| 54 |
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo |
|---|
| 55 |
# Import of LRRD CVS tree after renaming to Munin |
|---|
| 56 |
# |
|---|
| 57 |
# Revision 1.4 2003/12/18 16:55:45 jimmyo |
|---|
| 58 |
# Enabled multiple ports |
|---|
| 59 |
# |
|---|
| 60 |
# Revision 1.3 2003/12/18 16:35:33 jimmyo |
|---|
| 61 |
# fail more gracefully when using uninstalled perl modules. |
|---|
| 62 |
# |
|---|
| 63 |
# Revision 1.2 2003/11/07 17:43:16 jimmyo |
|---|
| 64 |
# Cleanups and log entries |
|---|
| 65 |
# |
|---|
| 66 |
# |
|---|
| 67 |
# |
|---|
| 68 |
# Magic markers: |
|---|
| 69 |
#%# family=auto |
|---|
| 70 |
#%# capabilities=autoconf |
|---|
| 71 |
|
|---|
| 72 |
my $ret = undef; |
|---|
| 73 |
if (! eval "require LWP::UserAgent;") |
|---|
| 74 |
{ |
|---|
| 75 |
$ret = "LWP::UserAgent not found"; |
|---|
| 76 |
} |
|---|
| 77 |
if (! eval "require Crypt::SSLeay;") |
|---|
| 78 |
{ |
|---|
| 79 |
$ret = "Crypt::SSLeay not found"; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
my $URLS = exists $ENV{'urls'} ? $ENV{'urls'} : "https://127.0.0.1:%d/server-status?auto"; |
|---|
| 83 |
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (443); |
|---|
| 84 |
|
|---|
| 85 |
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) |
|---|
| 86 |
{ |
|---|
| 87 |
if ($ret) |
|---|
| 88 |
{ |
|---|
| 89 |
print "no ($ret)\n"; |
|---|
| 90 |
exit 1; |
|---|
| 91 |
} |
|---|
| 92 |
my $ua = LWP::UserAgent->new(timeout => 30); |
|---|
| 93 |
my @badports; |
|---|
| 94 |
|
|---|
| 95 |
foreach my $port (@PORTS) { |
|---|
| 96 |
my $url = sprintf $URLS, $port; |
|---|
| 97 |
my $response = $ua->request(HTTP::Request->new('GET',$url)); |
|---|
| 98 |
push @badports, $port unless $response->is_success and $response->content =~ /Idle(?:Servers|Workers)/im; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
if (@badports) |
|---|
| 102 |
{ |
|---|
| 103 |
print "no (no apache server-status on ports @badports)\n"; |
|---|
| 104 |
exit 1; |
|---|
| 105 |
} |
|---|
| 106 |
else |
|---|
| 107 |
{ |
|---|
| 108 |
print "yes\n"; |
|---|
| 109 |
exit 0; |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) |
|---|
| 114 |
{ |
|---|
| 115 |
print "graph_title ApacheSSL processes\n"; |
|---|
| 116 |
print "graph_args --base 1000 -l 0\n"; |
|---|
| 117 |
print "graph_category apache\n"; |
|---|
| 118 |
print "graph_order "; |
|---|
| 119 |
foreach my $port (@PORTS) { |
|---|
| 120 |
print "busy$port idle$port "; |
|---|
| 121 |
} |
|---|
| 122 |
print "\n"; |
|---|
| 123 |
print "graph_vlabel processes\n"; |
|---|
| 124 |
print "graph_total total\n"; |
|---|
| 125 |
foreach my $port (@PORTS) { |
|---|
| 126 |
print "busy$port.label busy servers $port\n"; |
|---|
| 127 |
if (@PORTS == 1) { |
|---|
| 128 |
print "busy$port.draw AREA\n"; |
|---|
| 129 |
} |
|---|
| 130 |
else |
|---|
| 131 |
{ |
|---|
| 132 |
print "busy$port.draw LINE2\n"; |
|---|
| 133 |
} |
|---|
| 134 |
print "idle$port.label idle servers $port\n"; |
|---|
| 135 |
print "idle$port.draw STACK\n"; |
|---|
| 136 |
} |
|---|
| 137 |
exit 0; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
foreach my $port (@PORTS) |
|---|
| 141 |
{ |
|---|
| 142 |
my $ua = LWP::UserAgent->new(timeout => 30); |
|---|
| 143 |
my $url = sprintf $URLS, $port; |
|---|
| 144 |
my $response = $ua->request(HTTP::Request->new('GET',$url)); |
|---|
| 145 |
if ($response->content =~ /^Busy(?:Servers|Workers):\s+(.+)$/im) { |
|---|
| 146 |
print "busy$port.value $1\n"; |
|---|
| 147 |
} else { |
|---|
| 148 |
print "busy$port.value U\n"; |
|---|
| 149 |
} |
|---|
| 150 |
if ($response->content =~ /^Idle(?:Servers|Workers):\s+(.+)$/im) { |
|---|
| 151 |
print "idle$port.value $1\n"; |
|---|
| 152 |
} else { |
|---|
| 153 |
print "idle$port.value U\n"; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
# vim:syntax=perl |
|---|