Net/Statsd/Server/Backend/Console.pm

filter: Statementstmt 62.5% 15 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 55.8% 19 / 34 SCAR 0.5
CC
1
Cov
62%
init
2.0
flush
2.0
status
2.0
CRAP 1.1
« Net/Statsd/Server/Backend.pm ↑ Summary
1 # ABSTRACT: Console backend for Net::Statsd::Server
2  
3 package Net::Statsd::Server::Backend::Console;
4 {
5 1 $Net::Statsd::Server::Backend::Console::VERSION = '0.19';
6 }
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use base qw(Net::Statsd::Server::Backend);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub init {
15 0 ▶ my ($self) = @_;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 =cut
18 $self->{statsCache} = {
19 counters => {},
20 timers => {},
21 };
22 =cut
23  
24 0 $self->{json_emitter} = JSON::XS->new()
25 ->utf8(1)
26 ->shrink(1)
27 ->space_before(0)
28 ->space_after(0)
29 ->indent(0);
30 }
31  
32 sub flush {
33 0 ▶ my ($self, $timestamp, $metrics) = @_;
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
34  
35 0 print STDERR "Flushing stats at " . localtime($timestamp) . "\n";
36  
37 =cut
38  
39 WTF? Why does node-statsd do this at all?
40  
41 my $sc = $self->{statsCache};
42 for my $type (keys %{ $sc }) {
43 next unless $metrics->{$type};
44 for my $name (keys %{ $metrics->{$type} }) {
45 my $value = $metrics->{$type}->{$name};
46 $sc->{$type}->{$name} //= 0;
47 $sc->{$type}->{$name} += $value;
48 }
49 }
50  
51 =cut
52  
53 my $out = {
54 counters => $metrics->{counters},
55 timers => $metrics->{timers},
56 gauges => $metrics->{gauges},
57 timer_data => $metrics->{timer_data},
58 counter_rates => $metrics->{counter_rates},
59 sets => $metrics->{sets},
60 pctThreshold => $metrics->{pctThreshold},
61 0 };
62  
63 0 print STDERR $self->{json_emitter}->encode($out), "\n";
64 0 return;
65 }
66  
67 sub status {
68 0 ▶ my ($self) = @_;
Subroutine status: not called CC=1 SCAR=6.9
Pod undocumented
69 return {
70 last_flush => $self->since($self->{lastFlush}),
71 0 last_exception => $self->since($self->{lastException}),
72 };
73 }
74  
75 1 1;
« Net/Statsd/Server/Backend.pm ↑ Summary