Apache-Scoreboard

 view release on metacpan or  search on metacpan

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

    }
    else {
	$opts = {image => Apache::Scoreboard->image};
    }
    $opts->{host} ||= "";
    bless $opts, $class;
}

sub access {
    my($self, $args) = @_;
    my $image = $self->{image};
    my(@labels, @access, @bytes);
    my($total_access, $total_bytes);

    for (my $parent = $image->parent; $parent; $parent = $parent->next) {
	push @labels, $parent->pid;
	my $server = $parent->server;
	
	my $count = $server->access_count;
	push @access, $count;
	$total_access += $count;
	
	my $bytes = $server->bytes_served;
	push @bytes, $bytes / KB;
	$total_bytes += $bytes;
    }
    
    my $data = [\@labels, \@access, \@bytes];
    
    my $graph = Chart::PNGgraph::bars->new;
    
    $graph->set( 
		x_label => 'Child PID',
		y1_label => 'Access Count',
		y2_label => 'Bytes Served (KB)',
		title => "$self->{host} Server Access",
		long_ticks => 1,
		bar_spacing => 2,
		two_axes => 1,
		x_labels_vertical => 1,
		x_label_position => 1/2,
		dclrs => [qw(lred lblue)],
		%{ $args || {} },
	       );
    
    my $bytes_str = Apache::Scoreboard::size_string($total_bytes);
    
    $graph->set_legend("Access Count ($total_access total)", 
		       "Bytes Served (KB) ($bytes_str total)");

    ($graph, $data);
}

my %Status = 
  (
   '.' => "Open Slot",
   'S' => "Starting",
   '_' => "Waiting",
   'R' => "Reading",
   'W' => "Writing",
   'K' => "Keepalive",
   'L' => "Logging",
   'D' => "DNS Lookup",
   'G' => "Finishing",
  );

sub status {
    my($self, $args) = @_;
    my $image = $self->{image};
    my %data = ();
    my @labels = values %Status;
    
    for (my $parent = $image->parent; $parent; $parent = $parent->next) {
	my $server = $parent->server;
	$data{ $Status{ $server->status } }++;
    }
    
    my @nlabels = map { "$_ ($data{$_})" } keys %data;
    
    my $data = [\@nlabels, [@data{keys %data}]];
    
    my $graph = Chart::PNGgraph::pie->new(250, 250);
    
    $graph->set( 
		title => "$self->{host} Server Status",
		pie_height => 36,
		axislabelclr => 'black',
		'3d' => 0,
		start_angle => 90,
		%{ $args || {} },
	       );
    ($graph, $data);    
}

sub cpu {
    my($self, $args) = @_;
    my $image = $self->{image};
    my(@labels, @cpu, @req_time);
    my($total_cpu, $total_req_time);
    
    for (my $parent = $image->parent; $parent; $parent = $parent->next) {
	push @labels, $parent->pid;
	my $server = $parent->server;
	
	my $cpu = $server->times;
	push @cpu, $cpu;
	$total_cpu += $cpu;
	
	my $req_time = $server->req_time;
	push @req_time, $req_time;
	$total_req_time += $req_time;
    }
    
    my $data = [\@labels, \@cpu, \@req_time];
    
    my $graph = Chart::PNGgraph::bars->new;
    
    $graph->set( 
		x_label => 'Child PID',
		y1_label => 'CPU',
		y2_label => 'Request Time',



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