NAME

Parse::Apache::ServerStatus - Simple module to parse apache's server-status.

SYNOPSIS

use Parse::Apache::ServerStatus;

my $url = 'http://localhost/server-status';
# or http://localhost/server-status?auto

my $prs = Parse::Apache::ServerStatus->new(
   url     => 'http://localhost/server-status',
   timeout => 30
);

my $stat = $prs->get or die $prs->errstr;

# or

my $prs = Parse::Apache::ServerStatus->new;

foreach my $url (@urls) {
    $prs->request(url => $url, timeout => 30) or die $prs->errstr;
    my $stat = $prs->parse or die $prs->errstr;
}

# or both in one step

foreach my $url (@urls) {
    my $stat = $prs->get(url => $url, timeout => 30)
        or die $prs->errstr;
}

DESCRIPTION

This module parses the content of apache's server-status and countes the current status by each process. It works nicely with apache versions 1.3 and 2.x.

METHODS

new()

Call new() to create a new Parse::Apache::ServerStatus object.

request()

This method requests the url and safes the content into the object.

parse()

Call parse() to parse the server status. This method returns a hash reference with the parsed content. There are diffenrent keys that contains the following counts:

p    Parents (this key will be kicked in future releases, dont use it)
r    Requests currenty being processed
i    Idle workers
_    Waiting for Connection
S    Starting up
R    Reading Request
W    Sending Reply
K    Keepalive (read)
D    DNS Lookup
C    Closing connection
L    Logging
G    Gracefully finishing
I    Idle cleanup of worker
.    Open slot with no current process

The following keys are set to 0 if extended server-status is not activated.

ta   Total accesses
tt   Total traffic
rs   Requests per second
bs   Bytes per second
br   Bytes per request

It's possible to call parse() with the content as argument.

my $stat = $prs->parse($content);

If no argument is passed then parse() looks into the object for the content that is stored by request().

get()

get() calls request() and parse() in one step. It's possible to set the options url and timeout and it returns the hash reference that is returned by parse().

content()

Call content() if you need the full content of server-status.

my $content = $prs->content;

errstr()

errstr() contains the error string if the requests fails.

ua()

Access the LWP::UserAgent object if you want to set your own properties.

OPTIONS

There are only two options: url and timeout.

Set url with the complete url like http://localhost/server-status. There is only http supported by default, not https or other protocols.

Set timeout to define the time in seconds to abort the request if there is no response. The default is set to 180 seconds if the options isn't set.

EXAMPLE

use strict;
use warnings;
use Parse::Apache::ServerStatus;

$|++;
my $prs = Parse::Apache::ServerStatus->new(
    url => 'http://localhost/server-status',
    # url => 'http://localhost/server-status?auto',
    timeout => 10
);

my @order    = qw/p r i _ S R W K D C L G I . ta tt rs bs br/;
my $interval = 10;
my $header   = 20;

while ( 1 ) {
    print map { sprintf("%8s", $_) } @order;
    print "\n";
    for (my $i = 0; $i <= $header; $i++) {
        my $stat = $prs->get or die $prs->errstr;
        print map { sprintf("%8s", $stat->{$_}) } @order;
        print "\n";
        sleep($interval);
    }
}

EXAMPLE CONFIGURATION FOR APACHE

This is just an example to activate the handler server-status for localhost.

ExtendedStatus On
<Location /server-status>
    SetHandler server-status
    Order Deny,Allow
    Deny from all
    Allow from localhost
</Location>

into the configuration file.

PREREQUISITES

LWP::UserAgent
Params::Validate
Class::Accessor::Fast

EXPORTS

No exports.

REPORT BUGS

Please report all bugs to <jschulz.cpan(at)bloonix.de>.

AUTHOR

Jonny Schulz <jschulz.cpan(at)bloonix.de>.

COPYRIGHT

Copyright (C) 2007-2010 by Jonny Schulz. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.