Plack-Middleware-Statsd

 view release on metacpan or  search on metacpan

lib/Plack/Middleware/Statsd.pm  view on Meta::CPAN


Note: this was changed since version v0.9.0 in order to avoid leaking
personally identifiable information when the L</client> does not have
a secured connection to the statsd server.

=item C<psgi.request.content-length>

The content-length of the request, if it is specified in the header.

This is treated as a timing rather than a counter, so that statistics
can be saved.

=item C<psgi.request.content-type.$TYPE.$SUBTYPE>

A counter for the content type of request bodies is incremented, e.g.
C<psgi.request.content-type.application.x-www-form-urlencoded>.

Any modifiers in the type, e.g. C<charset>, will be ignored.

=item C<psgi.response.content-length>

The content-length of the response, if it is specified in the header.

This is treated as a timing rather than a counter, so that statistics
can be saved.

=item C<psgi.response.content-type.$TYPE.$SUBTYPE>

A counter for the content type is incremented, e.g. for a JPEG image,
the counter C<psgi.response.content-type.image.jpeg> is incremented.

Any modifiers in the type, e.g. C<charset>, will be ignored.

=item C<psgi.response.status.$CODE>

A counter for the HTTP status code is incremented.

=item C<psgi.response.time>

The response time, in ms.

As of v0.3.1, this is no longer rounded up to an integer. If this
causes problems with your statsd daemon, then you may need to use a
subclassed version of your statsd client to work around this.

=item C<psgi.response.x-sendfile>

This counter is incremented when the C<X-Sendfile> header is added.

The header is configured using the C<plack.xsendfile.type> environment
key, otherwise the C<HTTP_X_SENDFILE_TYPE> environment variable.

See L<Plack::Middleware::XSendfile> for more information.

=item C<psgi.worker.pid>

The worker PID is added to the set.

Note that this is set after the request is processed.  This means that
while the set size can be used to indicate the number of active
workers, if the workers are busy (i.e. longer request processing
times), then this will show a lower number.

This was added in v0.3.10.

=item C<psgix.harakiri>

This counter is incremented when the harakiri flag is set.

=back

If you want to rename these, or modify sampling rates, then you will
need to use a wrapper class for the L</client>.

=head1 EXAMPLES

=head2 Using from Catalyst

You can access the configured statsd client from L<Catalyst>:

  sub finalize {
    my $c = shift;

    if (my $statsd = $c->req->env->{'psgix.monitor.statsd'}) {
      ...
    }

    $c->next::method(@_);
  }

Alternatively, you can use L<Catalyst::Plugin::Statsd>.

=head2 Using with Plack::Middleware::SizeLimit

L<Plack::Middleware::SizeLimit> version 0.11 supports callbacks that
allow you to monitor process size information.  In your F<app.psgi>:

  use Net::Statsd::Tiny;
  use Try::Tiny;

  my $statsd = Net::Statsd::Tiny->new( ... );

  builder {

    enable "Statsd",
      client      => $statsd,
      sample_rate => 1.0;

    ...

    enable "SizeLimit",
      ...
      callback => sub {
          my ($size, $shared, $unshared) = @_;
          try {
              $statsd->timing_ms('psgi.proc.size', $size);
              $statsd->timing_ms('psgi.proc.shared', $shared);
              $statsd->timing_ms('psgi.proc.unshared', $unshared);
          }
          catch {
              warn $_;



( run in 2.622 seconds using v1.01-cache-2.11-cpan-f56aa216473 )