Apache-VMonitor
view release on metacpan or search on metacpan
lib/Apache/VMonitor.pm view on Meta::CPAN
require 5.006;
use strict;
use warnings;
use Template ();
BEGIN {
use constant MP2 => eval { require mod_perl2; $mod_perl2::VERSION >= 2.0 };
eval {require mod_perl} unless MP2;
die "mod_perl is required to run this module: $@" if $@;
if (MP2) {
require Apache2::ServerUtil;
require Apache2::RequestRec;
require Apache2::RequestIO;
require APR::Table;
require APR::Pool;
require Apache2::Const;
Apache2::Const->import('OK');
} else {
require Apache;
require Apache::Constants;
Apache::Constants->import('OK');
}
require Apache::Scoreboard;
require Time::HiRes;
}
# once 2.0 is released drop the Apache::MPM_IS_THREADED case
use constant APACHE_IS_THREADED => MP2 &&
require Apache2::MPM && Apache2::MPM->is_threaded();
# Apache::Scoreboard for 1.3 scoreboard has the vhost accessor only
# starting from version 0.12
use constant HAS_VHOSTS => (MP2 || $Apache::Scoreboard::VERSION > 0.11);
#use constant THREAD_LIMIT => MP2
# ? Apache::Const::THREAD_LIMIT
# : 0; # no threads in mp1
use constant SINGLE_PROCESS_MODE => MP2
? Apache2::ServerUtil::exists_config_define('ONE_PROCESS')
: Apache->define('X');
my $gtop;
eval {
require GTop;
$gtop = GTop->new;
};
my $tt;
%Apache::VMonitor::longflags = (
"_" => "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",
);
########################
# default config values
########################
%Apache::VMonitor::Config = (
# behavior
refresh => 0,
verbose => 0,
# sections to show
system => 1,
apache => 1,
procs => 0,
mount => 0,
fs_usage => 1,
# sorting
apache_sort_by => 'size',
apache_sort_by_ascend => 0,
);
my @sects = qw(system apache procs mount fs_usage verbose);
my %cfg = ();
sub handler_mp1 ($$) { &run }
sub handler_mp2 : method { &run }
*handler = MP2 ? \&handler_mp2 : \&handler_mp1;
my $counter = 0;
sub run {
my ($class, $r) = @_;
$class = ref($class)||$class;
#$tt = Template->new({});
my %params = MP2
? map({ split('=', $_, 2) } split /[&]/, $r->args)
: $r->args;
# modify the default args if requested
for (keys %Apache::VMonitor::Config) {
$cfg{$_} = exists $params{$_}
? $params{$_}
: $Apache::VMonitor::Config{$_};
}
my $pid = $params{pid} || 0;
# really just a worker index (in threaded mpm)
my $tid = $params{thread_num} || '';
# build the updated URL (append the pid k/v pair)
my $url = $r->uri . "?pid=$pid&" . join "&", map {"$_=$cfg{$_}"} keys %cfg;
lib/Apache/VMonitor.pm view on Meta::CPAN
sys and idle state
<B>3rd</B>: RAM utilization: total available, total used, free, shared
and buffered
<B>4th</B>: SWAP utilization: total available, total used, free, how
many paged in and out
},
apache =>
qq{
<B>Apache/mod_perl processes:</B>
The first row reports the status of parent process (mnemonic 'par').
Columns:
<pre>
<span class="item_even">Column Purpose</span>
<b>PID</b> Id (or Thread index for threaded httpd)
<b>Size</b> Total Size
<b>Share</b> Shared Size
<b>VSize</b> Virtual Size
<b>RSS</b> Resident Size
<b>M</b> Apache mode (See below a full table of abbreviations)
<b>Elapsed</b> Time since request was started if still in process (0 otherwise)
<b>LastReq</b> Time last request was served if idle now (0 otherwise)
<b>Srvd</b> How many requests were processed by this child
<b>Client</b> Client IP
<b>VHost</b> Virtual Hosts (httpd 2.0, if any configured)
<b>Request</b> Request (first 64 chars)
</pre>
<p> You can sort the report by clicking on any column (only
the parent process is outstanding and is not sorted)</p>
Last row reports:
<B>Total</B> = a total size of the httpd processes (by
summing the SIZE value of each process)
<B>Approximate real size (-shared)</B> =
1. For each process sum up the difference between shared and system
memory.
2. Now if we add the share size of the process with maximum
shared memory, we will get all the memory that actually is being
used by all httpd processes but the parent process.
Please note that this might be incorrect for your system, so you use
this number on your own risk. I have verified this number, by writing
it down and then killing all the servers. The system memory went down
by approximately this number. Again, use this number wisely!
The <B>modes</B> a process can be in:
<code><b>_</b></code> = Waiting for Connection<BR>
<code><b>S</b></code> = Starting up<BR>
<code><b>R</b></code> = Reading Request<BR>
<code><b>W</b></code> = Sending Reply<BR>
<code><b>K</b></code> = Keepalive (read)<BR>
<code><b>D</b></code> = DNS Lookup<BR>
<code><b>C</b></code> = Closing connection<BR>
<code><b>L</b></code> = Logging<BR>
<code><b>G</b></code> = Gracefully finishing<BR>
<code><b>I</b></code> = Idle cleanup of worker<BR>
<code><b>.</b></code> = Open slot with no current process<BR>
},
procs =>
qq{
<B> Processes matched by <CODE>\$Apache::VMonitor::PROC_REGEX</CODE> (PROCS)</B>
Setting:
<PRE>\$Apache::VMonitor::PROC_REGEX = join "\|", qw(httpd mysql squid);</PRE>
will display the processes that match /httpd|mysql|squid/ regex in a
top(1) fashion in groups of processes. After each group the report of
total size and approximate real size is reported (approximate == size
calculated with shared memory reducing)
At the end there is a report of total size and approximate real size.
},
mount =>
qq{
<B>Mount section</B>
Reports about all mounted filesystems
<B>DEVICE</B> = The name of the device<BR>
<B>MOUNTED ON</B> = Mount point of the mounted filesystem<BR>
<B>FS TYPE</B> = The type of the mounted filesystem<BR>
},
fs_usage =>
qq{
<B>File System usage</B>
Reports the utilization of all mounted filesystems:
<B>FS</B> = the mount point of filesystem<BR>
<B>Blocks (1k)</B> = Space usage in blocks of 1k bytes<BR>
<B>Total</B> = Total existing<BR>
<B>SU Avail</B> = Available to superuser (root) (tells how much space let for real)<BR>
<B>User Avail</B> = Available to user (non-root) (user cannot use last 5% of each filesystem)
<B>Usage</B> = utilization in percents (from user perspective, when it reaches
100%, there are still 5% but only for root processes)
<B>Files</B>: = File nodes usage<BR>
<B>Total</B> = Total nodes possible <BR>
<B>Avail</B> = Free nodes<BR>
<B>Usage</B> = utilization in percents<BR>
},
( run in 0.962 second using v1.01-cache-2.11-cpan-df04353d9ac )