Apache-VMonitor

 view release on metacpan or  search on metacpan

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

  FOR key = cols_sorted;
      col = cols.$key;
      times = col.$width - col.$label.length;
      spacing = times > 0 ? space.repeat(times) : "";
      "$spacing<a href=\"${col.$sort_link}\">${col.$label}</a>$space";
  END;
  "</b>\n";

  # records
  max_pid_len     = cols.pid.$width;
  max_client_len  = cols.client.$width;
  max_vhost_len   = cols.vhost.$width;
  max_request_len = cols.request.$width;

  # parent rec
  spacing_len = cols.mode.$width + cols.elapsed.$width + cols.lastreq.$width +
                cols.served.$width + max_client_len + max_vhost_len + 
                max_request_len + 11;

  USE format_parent =
      format("%s: %s %5s %5s %5s %5s %${spacing_len}s");

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

      format_parent(prec.id, pid_link, prec.fsize, prec.fshare, prec.fvsize,
                    prec.frss, space);
  END;

  fvhost = has_vhosts_entries 
         ? " %${max_vhost_len}.${max_vhost_len}s" 
         : "%0.0s";
  USE format_child =
      format("%s: %s %5s %5s %5s %5s %1s %s %s %4s %${max_client_len}.${max_client_len}s${fvhost} %s%s");

  # if prec is passed, that means that the parent process is also a worker
  # so present the process data on the same line with the worker data
  BLOCK present_worker_record;
      IF prec;
          wrec.id       = prec.id;
          wrec.pid      = prec.pid;
          wrec.pid_link = prec.pid_link;
          wrec.fsize    = prec.fsize;
          wrec.fshare   = prec.fshare;
          wrec.fvsize   = prec.fvsize;
          wrec.frss     = prec.frss;
      END;

      # alert on workers that are still at work for a single request
      # for more than 15 secs
      elapsed_class = wrec.elapsed > 15 ? "alert" : "normal";
      wrec.felapsed = "<span class=\"$elapsed_class\">${wrec.felapsed}</span>";

      # alert on workers that worked for a single request for more
      # than 15 secs
      lastreq_class = wrec.lastreq > 15 ? "alert" : "normal";
      wrec.flastreq = "<span class=\"$lastreq_class\">${wrec.flastreq}</span>";

      # escape HTML in request URI to prevent cross-site scripting attack
      wrec.frequest = HTML.escape(wrec.request);

      # line fill spacing (needed for coloured areas)
      times = max_request_len - wrec.frequest.length;
      line_fill = times > 0 ? space.repeat(times) : "";

      # pid linked
      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;
          ELSE;
              PROCESS present_parent_record prec = rec;
          END;
          "</span>\n";
      END;
  ELSE;
      FOR rec = records;
          item_class = loop.count % 2 ? "item_odd" : "item_even";
          "<span class=\"$item_class\">";
          IF rec.workers.size;
              PROCESS present_worker_record prec = rec, wrec => rec.workers.0;
          ELSE;
              PROCESS present_parent_record prec = rec;
          END;
          "</span>\n";
      END;
  END;

  # total apache proc memory usage
  USE format_total =
      format("\n<b>Total:     %5dK (%s) size, %6dK (%s) approx real size (-shared)</b>\n");
      format_total(total.size, total.fsize, total.shared, total.fshared);

-%]
</pre>
EOT

}

### procs ###

sub data_procs {
    my $self = shift;

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

       format("  %0${ptr_size}lx-%0${ptr_size}lx %0${ptr_size}lx - %02x:%02x %08lu - %4s - %s\n");
   FOR rec = mem_maps.records.sort('filename');
       format_map_item(rec.start, rec.end, rec.offset, rec.device_major, rec.device_minor, rec.inode, rec.perm, rec.filename);
   END;

  # loaded shared libs sizes
  "<hr><b>Loaded Libs Sizes:</b> (in bytes)\n\n";
   USE format_shared_lib = format("%10d (%s): %s\n");
   FOR rec = libs.records.sort('filename');
       format_shared_lib(rec.size, rec.fsize, rec.filename);
   END;
   USE format_shared_lib_total = format("\n<b>%10d (%s): %s</b>\n");
   format_shared_lib_total(libs.total, libs.ftotal, "Total");

-%]
</pre>
[% END %]

[% BLOCK single_httpd_process %]
[%-
  USE HTML;

  "<hr><b>httpd-specific Info:</b>\n\n";

  USE format_item = format("  <b>%-25s</b> : %s\n");
  format_item("Process type", rec.proc_type);

  format_item("Status", rec.mode_long);

  IF rec.elapsed;
      elapsed_class = rec.elapsed > 15 ? "alert" : "normal";
      rec.felapsed = "<span class=\"$elapsed_class\"><b>${rec.felapsed}</b></span>";
      format_item("Cur. req. is running for", rec.felapsed);
  ELSE;
      lastreq_class = rec.lastreq > 15 ? "alert" : "normal";
      rec.flastreq = "<span class=\"$lastreq_class\">${rec.flastreq}</span>";
      format_item("Last request processed in", rec.flastreq);
  END;

  format_item("", "");

  USE format_slot_header = format("<b>%16s</b>   <b>%16s</b>");
  slot_header = format_slot_header("This slot", "This child");
  format_item("", slot_header);

  USE format_slot_entry = format("%16s   %16s");
  slot_entry = format_slot_entry(rec.access_count, rec.my_access_count);
  format_item("Requests Served", slot_entry);

  USE format_slot_entry = format("(%8s) %5s   (%8s) %5s");
  slot_entry = format_slot_entry(rec.bytes_served,    rec.fbytes_served, 
                                 rec.my_bytes_served, rec.fmy_bytes_served);
  format_item("Bytes Transferred", slot_entry);

  format_item("", "");

  format_item("Client IP or DNS", rec.client);

  format_item("Virtual Host", rec.vhost) IF rec.vhost.length;

  # escape HTML in request URI to prevent cross-site scripting attack
  rec.frequest = HTML.escape(rec.request);
  format_item("Request (first 64 chars)", rec.frequest);

  format_item("", "");

  USE format_cpu_header = format("%8s  %8s  %8s  %8s  %8s");
  cpu_header = format_cpu_header("total", "utime", "stime", "cutime", "cstime");
  format_item("CPU times (secs)", cpu_header);
  USE format_cpu_data = format("%8d  %8d  %8d  %8d  %8d");
  cpu_data = format_cpu_data(rec.cpu_total, rec.cpu_utime, rec.cpu_stime, rec.cpu_cutime, rec.cpu_cstime);
  format_item("", cpu_data);

-%]
[% END %]
EOT

}



### fs_usage ###

sub data_fs_usage {
    my $self = shift;

    my($mountlist, $entries) = $gtop->mountlist(1);
    my $fs_number = $mountlist->number;

    # for formatting purpose find out the max length of the filesystems
    my $max_fs_name_len = 0;
    my %fs = ();
    for (my $i = 0; $i < $fs_number; $i++) {
        my $path = $entries->mountdir($i);
        $fs{$path} = $i;
        my $len = length $path;
        $max_fs_name_len = $len if $len > $max_fs_name_len;
    }

    $max_fs_name_len = 12 if $max_fs_name_len < 12;

    # the filesystems
    my @items = ();
    for my $path (sort keys %fs){
        my $i = $fs{$path};
        my $fsusage = $gtop->fsusage($entries->mountdir($i));

        my $total_blocks      = $fsusage->blocks / 2;
        my $su_avail_blocks   = $fsusage->bfree  / 2 ;
        my $user_avail_blocks = $fsusage->bavail / 2;
        my $used_blocks       = $total_blocks - $su_avail_blocks;
        my $usage_blocks      = $total_blocks 
            ? ($total_blocks - $user_avail_blocks)* 100 / $total_blocks
            : 0;
        my $total_files       = $fsusage->files;
        my $free_files        = $fsusage->ffree;
        my $usage_files       = $total_files 
            ? ($total_files - $free_files) * 100 / $total_files
            : 0;

        push @items, {
            path => $path,



( run in 0.994 second using v1.01-cache-2.11-cpan-39bf76dae61 )