Author: spadkins
Date: Sun Feb 19 22:16:53 2012
New Revision: 15168

Modified:
   p5ee/trunk/App-Context/lib/App/Context/POE/ClusterController.pm
   p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm

Log:
added simple HTTP URL for checking on what the current throttles for a 
particular tag are set to, access at http://server:port/throttles

Modified: p5ee/trunk/App-Context/lib/App/Context/POE/ClusterController.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/POE/ClusterController.pm     
(original)
+++ p5ee/trunk/App-Context/lib/App/Context/POE/ClusterController.pm     Sun Feb 
19 22:16:53 2012
@@ -289,6 +289,36 @@
     return($state);
 }
 
+sub throttles {
+    &App::sub_entry if ($App::trace);
+    my ($self) = @_;
+
+    my $datetime = time2str("%Y-%m-%d %H:%M:%S", time());
+    my $throttles = "Cluster Controller: 
$self->{host}:$self->{port}\n[$datetime]\n";
+    $throttles .= "\n";
+    $throttles .= $self->_throttles();
+
+    &App::sub_exit($throttles) if ($App::trace);
+    return($throttles);
+}
+
+sub _throttles {
+    &App::sub_entry if ($App::trace);
+    my ($self) = @_;
+
+    my $throttles = "";
+
+    ### TODO: Look up data sources
+    #for my $data_source (@$data_sources) {
+    #    $throttles .= sprintf("   %-16s %4s : %3d/%3d max : 
[Load:%4.1f][System Load:%4.1f][Mem:%5.1f%%/%7d][Swap:%5.1f%%/%7d] : 
[Up:%19s][Last:%19s]\n",
+    #}
+
+    $throttles .= $self->SUPER::_throttles();
+
+    &App::sub_exit($throttles) if ($App::trace);
+    return($throttles);
+}
+
 sub set_node_up {
     &App::sub_entry if ($App::trace);
     my ($self, $node, $sys_info) = @_;

Modified: p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        (original)
+++ p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        Sun Feb 19 
22:16:53 2012
@@ -71,11 +71,12 @@
         _start _stop _default poe_sigchld poe_sigterm poe_sigignore 
poe_shutdown poe_alarm poe_profile
         ikc_register ikc_unregister ikc_shutdown
         poe_run_event poe_event_loop_extension 
poe_dispatch_pending_async_events
-        poe_server_state poe_http_server_state poe_debug poe_http_debug 
poe_http_test_run
+        poe_server_state poe_throttles poe_http_server_state poe_debug 
poe_http_throttles poe_http_debug poe_http_test_run
         poe_enqueue_async_event poe_enqueue_async_event_finished 
poe_remote_async_event_finished
     )];
     $self->{poe_ikc_published_states} = [qw(
         poe_server_state
+        poe_throttles
         poe_enqueue_async_event
         poe_remote_async_event_finished
     )];
@@ -132,6 +133,7 @@
         'ADDRESS'  => INADDR_ANY,
         'PORT'     => $self->{options}{http_port},
         'HANDLERS' => [
+            { 'DIR' => '/throttles', 'SESSION' => $session_name, 'EVENT' => 
'poe_http_throttles', },
             { 'DIR' => '/debug', 'SESSION' => $session_name, 'EVENT' => 
'poe_http_debug', },
             { 'DIR' => '/testrun', 'SESSION' => $session_name, 'EVENT' => 
'poe_http_test_run', },
             { 'DIR' => '.*', 'SESSION' => $session_name, 'EVENT' => 
'poe_http_server_state', },
@@ -347,6 +349,54 @@
     return($state);
 }
 
+sub throttles {
+    &App::sub_entry if ($App::trace);
+    my ($self) = @_;
+
+    my $datetime = time2str("%Y-%m-%d %H:%M:%S", time());
+    my $throttles = "Server: $self->{host}:$self->{port}\n[$datetime]\n";
+    $throttles .= "\n";
+    $throttles .= $self->_throttles();
+
+    &App::sub_exit($throttles) if ($App::trace);
+    return($throttles);
+}
+
+sub _throttles {
+    &App::sub_entry if ($App::trace);
+    my ($self) = @_;
+
+    my $throttles = "";
+
+    my $options = $self->{options};
+    my $objects = $options->{init_objects};
+    my ($service_type, $name, $service);
+    foreach my $object (split(/ *[;,]+ */, $objects)) {
+        if ($object) {
+            if ($object =~ /^([A-Z][A-Za-z0-9]+)\.([A-Za-z0-9_-]+)$/) {
+                $service_type = $1;
+                $name = $2;
+            }
+            else {
+                $service_type = "SessionObject";
+                $name = $object;
+            }
+            $service = $self->service($service_type, $name);  # instantiate 
it. that's all.
+            if ($service->can("throttles")) {
+                $throttles .= "\n";
+                $throttles .= $service->throttles();
+            }
+        }
+    }
+
+    my $main_service = $self->{main_service};
+
+    $throttles .= "\n";
+
+    &App::sub_exit($throttles) if ($App::trace);
+    return($throttles);
+}
+
 sub _state_poe {
     my ($self) = @_;
     my $state = "";
@@ -1248,6 +1298,32 @@
     return RC_OK;
 }
 
+sub poe_throttles {
+    &App::sub_entry if ($App::trace);
+    my ( $self, $kernel, $heap ) = @_[ OBJECT, KERNEL, HEAP ];
+
+    my $throttles = $self->throttles();
+
+    &App::sub_exit($throttles) if ($App::trace);
+    return $throttles;
+}
+
+sub poe_http_throttles {
+    &App::sub_entry if ($App::trace);
+    my ( $self, $kernel, $heap, $request, $response ) = @_[ OBJECT, KERNEL, 
HEAP, ARG0, ARG1 ];
+
+    my $throttles = $kernel->call( $self->{poe_session_name}, 'poe_throttles' 
);
+    ### Build the response.
+    $response->code(RC_OK);
+    $response->push_header( "Content-Type", "text/plain" );
+    $response->content($throttles);
+    ### Signal that the request was handled okay.
+    $kernel->post( $self->{poe_kernel_http_name}, 'DONE', $response );
+
+    &App::sub_exit(RC_OK) if ($App::trace);
+    return RC_OK;
+}
+
 sub poe_debug {
     &App::sub_entry if ($App::trace);
     my ( $self, $kernel, $heap ) = @_[ OBJECT, KERNEL, HEAP ];

Reply via email to