Plack-Middleware-ServerStatus-Lite
view release on metacpan or search on metacpan
bin/server-status view on Meta::CPAN
next if $line =~ m/^\D/;
my ($ppid, $pid) = split /\s+/, $line, 2;
push @all_workers, $pid if $ppid == $parent_pid;
}
}
else {
# todo windows?
}
my $idle = 0;
my $busy = 0;
my $process_status = '';
my @process_status;
for my $pid ( @all_workers ) {
my $json = $stats->{$pid};
my $pstatus = eval {
$JSON->decode($json || '{}');
};
$pstatus ||= {};
if ( $pstatus->{status} && $pstatus->{status} eq 'A' ) {
$busy++;
}
else {
$idle++;
}
if ( defined $pstatus->{time} ) {
$pstatus->{ss} = time - $pstatus->{time};
}
$pstatus->{pid} ||= $pid;
delete $pstatus->{time};
delete $pstatus->{ppid};
delete $pstatus->{uptime};
$process_status .= sprintf "%s\n",
join(" ", map { defined $pstatus->{$_} ? $pstatus->{$_} : '' } qw/pid status remote_addr host method uri protocol ss/);
push @process_status, $pstatus;
}
$body .= <<EOF;
BusyWorkers: $busy
IdleWorkers: $idle
--
pid status remote_addr host method uri protocol ss
$process_status
EOF
chomp $body;
$status{BusyWorkers} = $busy;
$status{IdleWorkers} = $idle;
$status{stats} = \@process_status;
if ( $json ) {
print $JSON->encode(\%status);
}
else {
print $body;
}
exit(0);
lib/Plack/Middleware/ServerStatus/Lite.pm view on Meta::CPAN
my $kbytes = int($bytes / 1_000);
$body .= sprintf "Total Accesses: %s\n", $counter;
$body .= sprintf "Total kBytes: %s\n", $kbytes;
$status{TotalAccesses} = $counter;
$status{TotalKbytes} = $kbytes;
}
if ( my $scoreboard = $self->{__scoreboard} ) {
my $stats = $scoreboard->read_all();
my $idle = 0;
my $busy = 0;
my @all_workers = ();
my $parent_pid = getppid;
if ( $self->skip_ps_command ) {
# none
@all_workers = keys %$stats;
}
elsif ( $^O eq 'cygwin' ) {
my $ps = `ps -ef`;
lib/Plack/Middleware/ServerStatus/Lite.pm view on Meta::CPAN
my $process_status = '';
my @process_status;
for my $pid ( @all_workers ) {
my $json = $stats->{$pid};
my $pstatus = eval {
$JSON->decode($json || '{}');
};
$pstatus ||= {};
if ( $pstatus->{status} && $pstatus->{status} eq 'A' ) {
$busy++;
}
else {
$idle++;
}
if ( defined $pstatus->{time} ) {
$pstatus->{ss} = time - $pstatus->{time};
}
$pstatus->{pid} ||= $pid;
delete $pstatus->{time};
delete $pstatus->{ppid};
delete $pstatus->{uptime};
$process_status .= sprintf "%s\n",
join(" ", map { defined $pstatus->{$_} ? $pstatus->{$_} : '' } qw/pid status remote_addr host method uri protocol ss/);
push @process_status, $pstatus;
}
$body .= <<EOF;
BusyWorkers: $busy
IdleWorkers: $idle
--
pid status remote_addr host method uri protocol ss
$process_status
EOF
chomp $body;
$status{BusyWorkers} = $busy;
$status{IdleWorkers} = $idle;
$status{stats} = \@process_status;
}
else {
$body .= "WARN: Scoreboard has been disabled\n";
$status{WARN} = 'Scoreboard has been disabled';
}
if ( ($env->{QUERY_STRING} || '') =~ m!\bjson\b!i ) {
return [200, ['Content-Type' => 'application/json; charset=utf-8'], [ JSON::encode_json(\%status) ]];
}
( run in 0.432 second using v1.01-cache-2.11-cpan-87723dcf8b7 )