Apache-VMonitor

 view release on metacpan or  search on metacpan

lib/Apache/VMonitor.pm  view on Meta::CPAN

        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;

lib/Apache/VMonitor.pm  view on Meta::CPAN

        : $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;

    # if refresh is non-null, set the refresh header
    $r->headers_out->set(Refresh => "$cfg{refresh}; URL=$url") 
        if $cfg{refresh};

    MP2 ? $r->content_type('text/html') : $r->send_http_header('text/html');

lib/Apache/VMonitor.pm  view on Meta::CPAN

  fdate = format_date(date.month, date.day, date.year);

  USE format_time = format("%d:%.2d%s");
  pam = date.hour > 11 ? "pm" : "am";
  date.hour = date.hour - 12 IF date.hour > 11;
  ftime = format_time(date.hour, date.min, pam);

  USE format_load = format("%.2f %.2f %.2f");
  floadavg = format_load(loadavg.0, loadavg.1, loadavg.2,);

  USE format_run_procs = format(", %d processes/threads: %d running");
  frun_procs = tasks
      ? format_run_procs(tasks.0, tasks.1)
      : "";

  USE format_line_time_load =
      format("<b>%s %s  up %s, load average: %s%s</b>\n");
  format_line_time_load(fdate, ftime, uptime, floadavg, frun_procs);


  # CPU

lib/Apache/VMonitor.pm  view on Meta::CPAN

        # already, is there another way to get to the parent proc?)
        # handle the parent case
        if ($pmem && $pmem->{size}) {
            my $prec = {
                id        => 0,
                pid       => $ppid,
                pid_link  => fixup_url($self->{url}, pid => $ppid),
                %$pmem,
            };
            $data{ $ppid }{process} = $prec;
            # this parent has no worker threads
            $data{ $ppid }{workers} = [];
        }
    }

    my $SERVER_LIMIT = MP2 ? $image->server_limit : $Apache::Constants::HARD_SERVER_LIMIT;

    my $i;
    my $parent_count = 0;
    my ($parent_score, $worker_score, $pid);
    for ($i=0; $i < $SERVER_LIMIT; $i++) {

lib/Apache/VMonitor.pm  view on Meta::CPAN

        my %record = %$mem;

        $record{pid} = $pid;
        $record{id}  = $parent_count;

        $data{ $pid }{process} = \%record;

        if (APACHE_IS_THREADED) {
            do {
                my $record = $self->score2record($worker_score);
                my $thread_num = $worker_score->thread_num;
                $record->{pid}      = $thread_num;
                $record->{pid_link} = fixup_url($self->{url}, pid => $pid);
                $record->{pid_link} .= "&thread_num=$thread_num";
                push @{ $data{$pid}{workers} }, $record;
                $worker_score = 
                    $parent_score->next_live_worker_score($worker_score);
            } while $worker_score
        }
        else {
            push @{ $data{$pid}{workers} },
                $self->score2record($worker_score);
        }
    }

lib/Apache/VMonitor.pm  view on Meta::CPAN

            ? sub { $data{$a}{process}{$sort_field} <=> $data{$b}{process}{$sort_field} }
            : sub { $data{$b}{process}{$sort_field} <=> $data{$a}{process}{$sort_field} };
    }

    # it's a pity to waste display space on vhosts if none is configured
    my $has_vhosts_entries = 0;
    for my $pid (sort $sort_sub keys %data) {

        my $rec = $data{$pid}{process};

        # threads 
        my @workers = ();
        my $tcount = 0;
        for my $trec (@{ $data{$pid}{workers} || []}) {
            $tcount++;

            my $lastreq = $trec->{lastreq} ? $trec->{lastreq}/1000 : 0;
            $has_vhosts_entries++ if exists $trec->{vhost} && length $trec->{vhost};

            push @workers, {
                id        => sprintf("%03d", $tcount),

lib/Apache/VMonitor.pm  view on Meta::CPAN

    # remove the vhost col if there are no vhosts to display
    @cols_sorted = grep { $_ ne 'vhost' } @cols_sorted 
        unless $has_vhosts_entries;

    return {
        total       => $total,
        records     => \@records,
        cols_sorted => \@cols_sorted,
        cols        => \%cols,
        has_vhosts_entries  => $has_vhosts_entries,
        threaded    => (APACHE_IS_THREADED ? 1 : 0),
    };
}

sub pid2mem {
    my($self, $pid, $total) = @_;

    return {} unless $gtop;

    my $proc_mem = $gtop->proc_mem($pid);
    my $size  = $proc_mem ? $proc_mem->size($pid) : 0;

lib/Apache/VMonitor.pm  view on Meta::CPAN

      times = max_pid_len - wrec.pid.length;
      spacing = times > 0 ? space.repeat(times) : "";
      pid_link = "$spacing<a href=\"${wrec.pid_link}\">${wrec.pid}</a>";

      format_child(wrec.id, pid_link, wrec.fsize, wrec.fshare, wrec.fvsize,
                   wrec.frss, wrec.mode, wrec.felapsed, wrec.flastreq,
                   wrec.fserved, wrec.client, wrec.vhost, wrec.frequest, line_fill);
  END;


  IF threaded;
      FOR rec = records;
          item_class = loop.count % 2 ? "item_odd" : "item_even";
          "<span class=\"$item_class\">";
          IF rec.workers.size;
              PROCESS present_parent_record prec = rec;
              "\n";
              FOR wrec = rec.workers;
                  PROCESS present_worker_record prec = 0, wrec = wrec;
                  "\n";
              END;

lib/Apache/VMonitor.pm  view on Meta::CPAN


   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)

t/TEST.PL  view on Meta::CPAN


# sub-class Apache::TestRunPerl
package MyTest;

# 5.005-compat
BEGIN {
    require Apache::TestRunPerl;
    @MyTest::ISA = qw(Apache::TestRunPerl);
}

# so we get a nice view of procs/threads
use constant MIN_MAXCLIENTS => 5;

# subclass new_test_config to add some config vars which will be
# replaced in generated httpd.conf
sub new_test_config {
    my $self = shift;

    $self->{conf_opts}->{maxclients} ||= MIN_MAXCLIENTS;

    return $self->SUPER::new_test_config;



( run in 0.493 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )