Apache-VMonitor
view release on metacpan or search on metacpan
lib/Apache/VMonitor.pm view on Meta::CPAN
return \ <<'EOT';
<hr>
<pre>
[%-
header = "%-${len.devname}s %-${len.mountdir}s %-${len.type}s";
USE format_header = format("<b>$header</b>\n");
format_header("DEVICE", "MOUNTED ON", "FS TYPE");
USE format_item =
format("$header\n");
FOREACH item = items;
format_item(item.devname,
item.mountdir,
item.type
);
END;
-%]
</pre>
EOT
}
### verbose ###
%Apache::VMonitor::abbreviations =
(
verbose =>
qq{
<B>Verbose option</B>
Enables Verbose mode - displays an explanation and abbreviation
table for each enabled section.
},
refresh =>
qq{
<B>Refresh Section</B>
You can tune the automatic refresh rate by clicking on the
number of desired rate (in seconds). 0 (zero) means "no
automatic refresh".
},
system =>
qq{
<B>Top section</B>
Represents the emulation of top utility, while individually
reporting only on httpd processes, and provides information
specific to these processes.
<B>1st</B>: current date/time, uptime, load average: last 1, 5 and 15
minutes, total number of processes and how many are in the
running state.
<B>2nd</B>: CPU utilization in percents: by processes in user, nice,
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>
},
);
sub data_verbose {
my $self = shift;
return {
abbr => \%Apache::VMonitor::abbreviations,
cfg => \%cfg,
};
}
sub tmpl_verbose {
return \ <<'EOT';
[%-
FOR item = cfg.keys.sort;
NEXT UNLESS abbr.$item;
NEXT UNLESS cfg.$item OR $item == "refresh";
note = abbr.$item;
note = note.replace('^',"<p>");
note = note.replace("\n\n","</p>\n");
note = note.replace('$',"<hr>");
note;
END;
-%]
EOT
}
### helpers ###
# Takes seconds as int or float as an argument
#
# Returns string of time in days (12d) or
# hours/minutes (11:13) if less then one day,
# and secs.millisec (12.234s) if less than a minute
#
# The returned sting is always of 6 digits length (taken that
# length(int days)<4) so you can ensure the column with
# printf "%7s", format_time($secs)
###############
sub format_time {
my $secs = shift || 0;
return sprintf "%6.3fs", $secs if $secs < 60;
my $hours = $secs / 3600;
return sprintf "%6.2fd", $hours / 24 if $hours > 24;
return sprintf " %02d:%2.2dm", int $hours,
int $secs%3600 ? int (($secs%3600)/60) : 0;
}
# XXX: a faster C equivalent?
#
lib/Apache/VMonitor.pm view on Meta::CPAN
=item 1
For each process sum up the difference between shared and total
memory.
=item 2
Now if we add the share size of the process with maximum shared
memory, we will get all the memory that is actually used by all
mod_perl processes, but the parent process.
=back
Please note that this might be incorrect for your system, so you
should use this number on your own risk. We have verified this number
on the Linux OS, by taken the number reported by C<Apache::VMonitor>,
then stopping mod_perl and looking at the system memory usage. The
system memory went down approximately by the number reported by the
tool. Again, use this number wisely!
If you don't want the mod_perl processes section to be displayed set:
$Apache::VMonitor::Config{apache} = 0;
The default is to display this section.
=item top(1) emulation (any processes)
This section, just like the mod_perl processes section, displays the
information in a top(1) fashion. To enable this section you have to
set:
$Apache::VMonitor::Config{procs} = 1;
The default is not to display this section.
Now you need to specify which processes are to be monitored. The
regular expression that will match the desired processes is required
for this section to work. For example if you want to see all the
processes whose name include any of these strings: I<http>, I<mysql>
and I<squid>, the following regular expression is to be used:
$Apache::VMonitor::PROC_REGEX = join "\|", qw(httpd mysql squid);
=item mount(1) emulation
This section reports about mounted filesystems, the same way as if you
have called mount(1) with no parameters.
If you want the mount(1) section to be displayed set:
$Apache::VMonitor::Config{mount} = 1;
The default is NOT to display this section.
=item df(1) emulation
This section completely reproduces the df(1) utility. For each mounted
filesystem it reports the number of total and available blocks (for
both superuser and user), and usage in percents.
In addition it reports about available and used file inodes in numbers
and percents.
This section has a capability of visual alert which is being triggered
when either some filesystem becomes more than 90% full or there are
less than 10% of free file inodes left. When this event happens the
filesystem related report row will be displayed in the bold font and
in the red color.
If you don't want the df(1) section to be displayed set:
$Apache::VMonitor::Config{fs_usage} = 0;
The default is to display this section.
=item abbreviations and hints
The monitor uses many abbreviations, which might be knew for you. If
you enable the VERBOSE mode with:
$Apache::VMonitor::Config{verbose} = 1;
this section will reveal all the full names of the abbreviations at
the bottom of the report.
The default is NOT to display this section.
=back
=head1 CONFIGURATION
To enable this module you should modify a configuration in
B<httpd.conf>, if you add the following configuration:
<Location /system/vmonitor>
SetHandler perl-script
PerlHandler Apache::VMonitor
</Location>
The monitor will be displayed when you request
http://localhost/system/vmonitor or alike.
You probably want to protect this location, from unwanted visitors. If
you are accessing this location from the same IP address, you can use
a simple host based authentication:
<Location /system/vmonitor>
SetHandler perl-script
PerlHandler Apache::VMonitor
order deny, allow
deny from all
allow from 132.123.123.3
</Location>
Alternatively you may use the Basic or other authentication schemes
provided by Apache and various extensions.
You can control the behavior of this module by configuring the
following variables in the startup file or inside the
C<E<lt>PerlE<gt>> section.
( run in 1.294 second using v1.01-cache-2.11-cpan-39bf76dae61 )