Permalink
Browse files

add /stats for basic statistical information about subscribers

  • Loading branch information...
revmischa committed Jan 16, 2012
1 parent 2eb3979 commit 83694001106390fcf49e98739443bfd7d3a1a738
Showing with 36 additions and 3 deletions.
  1. +17 −1 README
  2. +17 −0 eg/event_server.psgi
  3. +2 −2 lib/Web/Hippie/PubSub.pm
View
18 README
@@ -18,7 +18,9 @@ SYNOPSIS
builder {
# mount hippie server
mount '/_hippie' => builder {
enable "+Web::Hippie::PubSub", bus => $bus;
enable "+Web::Hippie::PubSub",
keep_alive => 30, # send 'ping' event every 30 seconds
bus => $bus;
sub {
my $env = shift;
my $args = $env->{'hippie.args'};
@@ -29,6 +31,10 @@ SYNOPSIS
mount '/' => my $app;
};
ATTRIBUTES
Number of seconds between keep-alive events. ZMQ::Server will send a
"ping" event to keep connections alive. Set to zero to disable.
DESCRIPTION
This module adds publish/subscribe capabilities to Web::Hippie using
AnyMQ.
@@ -51,3 +57,13 @@ LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
POD ERRORS
Hey! The above document had some coding errors, which are explained
below:
Around line 198:
Unknown directive: =title
Around line 204:
Unknown directive: =title
View
@@ -27,6 +27,11 @@ sub fatal {
cluck "Fatal error when handling request: $err\n";
}
# stats
our $total_subscribers = 0;
our $current_subscribers = 0;
our $events_published = 0;
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
@@ -37,6 +42,14 @@ my $app = sub {
if ($req->path eq '/') {
# index
$res->redirect('/static/events.html');
} elsif ($req->path eq '/stats') {
# print out statistical information
my $ret = qq/
total_subscribers: $total_subscribers
current_subscribers: $current_subscribers
published_events: $events_published
/;
$res->content($ret);
} else {
# unknown path
$res->content("Unknown path " . $req->path);
@@ -70,11 +83,15 @@ builder {
if ($path eq '/new_listener') {
warn "Got new listener on channel $channel\n";
$current_subscribers++;
$total_subscribers++;
} elsif ($path eq '/message') {
my $msg = $env->{'hippie.message'};
$events_published++;
warn "Posting message to channel $channel\n";
} elsif ($path eq '/error') {
# client disconnected
$current_subscribers--;
} else {
warn "Unknown hippie event: $path\n";
}
View
@@ -195,13 +195,13 @@ Web::Hippie::PubSub - Comet/Long-poll event server using AnyMQ
=over 4
=title bus
=head2 bus
=cut
AnyMQ bus configured for publish/subscribe events
=title keep_alive
=head2 keep_alive
Number of seconds between keep-alive events. ZMQ::Server will send a
"ping" event to keep connections alive. Set to zero to disable.

0 comments on commit 8369400

Please sign in to comment.