root / plugins / apache / apache_average_requests @ 4771fd2b
Historique | Voir | Annoter | Télécharger (2,89 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# -*- cperl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
apache_average_request - Munin plugin to monitor the average request to |
| 7 |
Apache servers. It handles a list of ports passed in from a plugin |
| 8 |
configuration file. |
| 9 |
|
| 10 |
=head1 APPLICABLE SYSTEMS |
| 11 |
|
| 12 |
Apache HTTP servers with C</server-status> enabled. |
| 13 |
|
| 14 |
=head1 CONFIGURATION |
| 15 |
|
| 16 |
Enable stats in apache first!: |
| 17 |
|
| 18 |
<VirtualHost 127.0.0.1:80> |
| 19 |
<Location /server-status> |
| 20 |
SetHandler server-status |
| 21 |
AuthUserFile /route/to/auth.file |
| 22 |
AuthName Login-Stats |
| 23 |
AuthType Basic |
| 24 |
require valid-user |
| 25 |
</Location> |
| 26 |
</VirtualHost> |
| 27 |
|
| 28 |
And now in munin conf: |
| 29 |
|
| 30 |
[apache_*] |
| 31 |
env.url http://USER:PASS@127.0.0.1/server-status?auto |
| 32 |
env.ports 80 |
| 33 |
|
| 34 |
=head1 AUTHOR |
| 35 |
|
| 36 |
Ricardo Fraile <rfrail3@yahoo.es> |
| 37 |
Unknown |
| 38 |
|
| 39 |
=head1 LICENSE |
| 40 |
|
| 41 |
GPLv2 |
| 42 |
|
| 43 |
=head1 MAGIC MARKERS |
| 44 |
|
| 45 |
#%# family=auto |
| 46 |
#%# capabilities=autoconf |
| 47 |
|
| 48 |
=cut |
| 49 |
|
| 50 |
use strict; |
| 51 |
use warnings; |
| 52 |
use Munin::Plugin; |
| 53 |
|
| 54 |
my $ret = undef; |
| 55 |
|
| 56 |
if (! eval "require LWP::UserAgent;") |
| 57 |
{
|
| 58 |
$ret = "LWP::UserAgent not found"; |
| 59 |
if ( ! defined $ARGV[0] ) {
|
| 60 |
die $ret; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto";
|
| 65 |
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
|
| 66 |
|
| 67 |
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) |
| 68 |
{
|
| 69 |
if ($ret) |
| 70 |
{
|
| 71 |
print "no ($ret)\n"; |
| 72 |
exit 0; |
| 73 |
} |
| 74 |
|
| 75 |
my $ua = LWP::UserAgent->new(timeout => 30); |
| 76 |
|
| 77 |
foreach my $port (@PORTS) {
|
| 78 |
my $url = sprintf $URL, $port; |
| 79 |
my $response = $ua->request(HTTP::Request->new('GET',$url));
|
| 80 |
if ($response->is_success) {
|
| 81 |
if ($response->content =~ /^Total Accesses:/im ){
|
| 82 |
next; |
| 83 |
} |
| 84 |
else {
|
| 85 |
print "no (ExtendedStatus option for apache" |
| 86 |
. " mod_status is missing on port $port)\n"; |
| 87 |
exit 0; |
| 88 |
} |
| 89 |
} |
| 90 |
elsif ($response->code == 404) {
|
| 91 |
print "no (apache server-status not found. check if mod_status is enabled)\n"; |
| 92 |
exit 0; |
| 93 |
} |
| 94 |
else {
|
| 95 |
print "no (Port $port: ". $response->message .")\n"; |
| 96 |
exit 0; |
| 97 |
} |
| 98 |
} |
| 99 |
print "yes\n"; |
| 100 |
exit 0; |
| 101 |
} |
| 102 |
|
| 103 |
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) |
| 104 |
{
|
| 105 |
|
| 106 |
print "graph_title Average apache request\n"; |
| 107 |
print "graph_title Average apache Requests per second\n"; |
| 108 |
print "graph_vlabel average reqs/sec\n"; |
| 109 |
print "graph_scale no\n"; |
| 110 |
print "graph_category apache\n"; |
| 111 |
print "request.label Average apache reqs/sec\n"; |
| 112 |
exit 0; |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
my $ua = LWP::UserAgent->new(timeout => 30); |
| 117 |
|
| 118 |
foreach my $port (@PORTS) {
|
| 119 |
my $url = sprintf $URL, $port; |
| 120 |
my $response = $ua->request(HTTP::Request->new('GET',$url));
|
| 121 |
if ($response->content =~ /^ReqPerSec:\s+(.+)$/im) {
|
| 122 |
print "request.value $1\n"; |
| 123 |
} else {
|
| 124 |
print "request.value U\n"; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
# vim:syntax=perl |
