line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Console backend for Net::Statsd::Server |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::Statsd::Server::Backend::Console; |
4
|
|
|
|
|
|
|
$Net::Statsd::Server::Backend::Console::VERSION = '0.20'; |
5
|
1
|
|
|
1
|
|
426
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
7
|
1
|
|
|
1
|
|
3
|
use JSON::XS (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use base qw(Net::Statsd::Server::Backend); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
223
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
$self->{statsCache} = { |
16
|
|
|
|
|
|
|
counters => {}, |
17
|
|
|
|
|
|
|
timers => {}, |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$self->{json_emitter} = JSON::XS->new() |
22
|
|
|
|
|
|
|
->utf8(1) |
23
|
|
|
|
|
|
|
->shrink(1) |
24
|
|
|
|
|
|
|
->space_before(0) |
25
|
|
|
|
|
|
|
->space_after(0) |
26
|
|
|
|
|
|
|
->indent(0); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub flush { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $timestamp, $metrics) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
print STDERR "Flushing stats at " . localtime($timestamp) . "\n"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
WTF? Why does node-statsd do this at all? |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $sc = $self->{statsCache}; |
39
|
|
|
|
|
|
|
for my $type (keys %{ $sc }) { |
40
|
|
|
|
|
|
|
next unless $metrics->{$type}; |
41
|
|
|
|
|
|
|
for my $name (keys %{ $metrics->{$type} }) { |
42
|
|
|
|
|
|
|
my $value = $metrics->{$type}->{$name}; |
43
|
|
|
|
|
|
|
$sc->{$type}->{$name} //= 0; |
44
|
|
|
|
|
|
|
$sc->{$type}->{$name} += $value; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $out = { |
51
|
|
|
|
|
|
|
counters => $metrics->{counters}, |
52
|
|
|
|
|
|
|
timers => $metrics->{timers}, |
53
|
|
|
|
|
|
|
gauges => $metrics->{gauges}, |
54
|
|
|
|
|
|
|
timer_data => $metrics->{timer_data}, |
55
|
|
|
|
|
|
|
counter_rates => $metrics->{counter_rates}, |
56
|
|
|
|
|
|
|
sets => $metrics->{sets}, |
57
|
|
|
|
|
|
|
pctThreshold => $metrics->{pctThreshold}, |
58
|
0
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
print STDERR $self->{json_emitter}->encode($out), "\n"; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub status { |
65
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
66
|
|
|
|
|
|
|
return { |
67
|
|
|
|
|
|
|
last_flush => $self->since($self->{lastFlush}), |
68
|
0
|
|
|
|
|
|
last_exception => $self->since($self->{lastException}), |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |