| 1 | package Catalyst::Plugin::Statsd; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Log Catalyst stats to statsd | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use POSIX qw/ ceil /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Ref::Util qw/ is_plain_arrayref /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use experimental qw/ signatures /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # RECOMMEND PREREQ: Ref::Util::XS | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 2 | requires qw/ log_stats /; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = 'v0.10.1'; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub statsd_client($c) { | ||||||||||||||||||||||||||||||
|
Subroutine
statsd_client: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 24 | 2 | return $c->req->env->{'psgix.monitor.statsd'}; | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | sub statsd_metric_name_filter( $c, $stat ) { | ||||||||||||||||||||||||||||||
|
Subroutine
statsd_metric_name_filter: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | return "$stat" unless is_plain_arrayref($stat); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 6 | my $metric = "catalyst.stats." . $stat->[1] . ".time"; | |||||||||||||||||||||||||||||||
| 34 | 6 | $metric =~ s/[^\w\-_]+/./g; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 6 | return $metric; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | around log_stats => sub ( $next, $c ) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | state $config = $c->config->{'Plugin::Statsd'} // {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$c->config->{"Plugin::Statsd"} // {}
MC/DC0%0/1
$c->config->{"Plugin::Statsd"} // {}
$c->config->{"Plugin::Statsd"}
Truth table50%1/2
A
A= $c->config->{"Plugin::Statsd"}
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | if ( my $client = $c->statsd_client) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 2 | my $stat = [ -1, "catalyst.response.time", $c->stats->elapsed ]; | |||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | my $metric = $c->statsd_metric_name_filter($stat) or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 2 | $client->timing_ms( "catalyst.response.time", | |||||||||||||||||||||||||||||||
| 49 | ceil( $stat->[2] * 1000 ) ); | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 2 | foreach my $stat ( $c->stats->report ) { | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $metric = $c->statsd_metric_name_filter($stat) or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 4 | my $timing = ceil( $stat->[2] * 1000 ); | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 4 | $client->timing_ms( $metric, $timing ); | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | my $disabled = $config->{disable_stats_report} // !$c->debug; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"disable_stats_report"} // !$c->debug
MC/DC0%0/1
$config->{"disable_stats_report"} // !$c->debug
$config->{"disable_stats_report"}
Truth table50%1/2
A
A= $config->{"disable_stats_report"}
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | $c->$next unless $disabled; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 2 | }; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | around finalize => sub ( $next, $c ) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=25.9
| |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | if (my $secure = $c->req->env->{'psgix.monitor.statsd_secure_set_add'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | if ($c->can("sessionid") && (my $id = $c->sessionid)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$c->can("sessionid") and my $id = $c->sessionid
MC/DC0%0/2
$c->can("sessionid") and my $id = $c->sessionid
$c->can("sessionid")
my $id = $c->sessionid
Truth table33%1/3
A and B
A= $c->can("sessionid")B= my $id = $c->sessionid
| |||||||||||||||||||||||||||||||||
| 72 | 2 | $secure->("catalyst.sessionid", "$id"); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | # Plack::Middleware::Session | ||||||||||||||||||||||||||||||||
| 75 | elsif (my $options = $c->req->env->{'psgix.session.options'}) { | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (my $id = $options->{id}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 0 | $secure->("catalyst.sessionid", "$id"); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 2 | $c->$next(); | |||||||||||||||||||||||||||||||
| 83 | 2 | }; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 2 | 1; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||