LEMONLDAP::NG : status module in progress...

Little bug in Handler.pm : local cache was not purged when using logout_sso
environments/ppa-mbqj77/deployments/1
Xavier Guimard 17 years ago
parent 62a2742b06
commit 0213945fdf
  1. 6
      modules/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Simple.pm
  2. 62
      modules/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Status.pm

@ -493,7 +493,9 @@ sub forbidden {
if ( $datas->{_logout} ) {
print $statusPipe $datas->{$whatToTrace} . " => $_[0] LOGOUT\n"
if ($statusPipe);
return $class->goToPortal( $datas->{_logout}, 'logout=1' );
my $u = $datas->{_logout};
$class->localUnlog;
return $class->goToPortal( $u, 'logout=1' );
}
print $statusPipe $datas->{$whatToTrace} . " => $_[0] REJECT\n"
if ($statusPipe);
@ -710,7 +712,7 @@ sub status($$) {
$class->lmLog( "$class: request for status", 'debug' );
return SERVER_ERROR unless ( $statusPipe and $statusOut );
$r->handler("perl-script");
print $statusPipe "STATUS\n";
print $statusPipe "STATUS". ( $r->args ? " " . $r->args : '' ) . "\n";
my $buf;
while (<$statusOut>) {
last if (/^END$/);

@ -2,33 +2,79 @@ package Lemonldap::NG::Handler::Status;
use strict;
our $status = {};
our $status = {};
our $activity = [];
our $start = int( time / 60 );
use constant MN_COUNT => 10;
sub run {
my ( $localStorage, $localStorageOptions ) = ( shift, shift );
my $refLocalStorage;
eval "use $localStorage; \$refLocalStorage = new $localStorage(\$localStorageOptions);";
eval
"use $localStorage; \$refLocalStorage = new $localStorage(\$localStorageOptions);";
die($@) if ($@);
$| = 1;
my ( $lastMn, $mn );
while (<STDIN>) {
$mn = int( time / 60 ) - $start;
# Cleaning activity array
if ( $mn > $lastMn ) {
for ( my $i = 0 ; $i < $mn - $lastMn ; $i++ ) {
unshift @$activity, {};
delete $activity->[MN_COUNT];
}
}
$lastMn = $mn;
# Activity collect
if (/^(\S+)\s+=>\s+(\S+)\s+(OK|REJECT|REDIRECT|LOGOUT)$/) {
my ( $user, $uri, $code ) = ( $1, $2, $3 );
# Per user activity
$status->{user}->{$user}->{$code}++;
# Per uri activity
$uri =~ s/^(.*?)\?.*$/$1/;
$status->{uri}->{$uri}->{$code}++;
# Last 5 minutes activity
$activity->[0]->{$code}++;
}
elsif (/^STATUS$/) {
my $c;
# Status requests
# $args conatins parameters passed to url status page (a=1 for example
# if request is http://test.example.com/status?a=1). To be used
# later...
elsif (/^STATUS(?:\s+(\S+))?$/) {
my $args = $1;
my ( $c, $a, $u );
while ( my ( $user, $v ) = each( %{ $status->{user} } ) ) {
$u++;
# Total requests
foreach ( keys %$v ) {
$c->{$_} += $v->{$_};
}
}
foreach my $mn (@$activity) {
$a->{$_} += $mn->{$_} foreach ( keys %$mn );
}
foreach ( keys %$a ) {
$a->{$_} = sprintf( "%.2f", $a->{$_} / MN_COUNT );
$a->{$_} = int( $a->{$_} ) if ( $a->{$_} > 99 );
}
# DEVEL
use Data::Dumper;
print Dumper($c);
my @t = $refLocalStorage->get_keys( $localStorageOptions->{namespace} );
print "Local Cache : " . @t . " objects\n";
#use Data::Dumper;
#print Dumper( $c, $a, $status );
my @t =
$refLocalStorage->get_keys( $localStorageOptions->{namespace} );
print "TOTAL\n";
print sprintf("%-10s : %d\n", $_, $c->{$_}) foreach(sort keys %$c);
print "\nAVERAGE\n";
print sprintf("%-10s : %s\n", $_, $a->{$_}) foreach(sort keys %$a);
print "\nUsers : $u\n\nLocal Cache : " . @t . " objects\n";
print "END\n";
}
}

Loading…
Cancel
Save