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
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$Net::Statsd::Server::Backend::Console::VERSION = '0.17'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
849
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
6
|
use JSON::XS (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use base qw(Net::Statsd::Server::Backend); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
459
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
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
|
|
|
0
|
0
|
|
my ($self, $timestamp, $metrics) = @_; |
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
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
print STDERR $self->{json_emitter}->encode($out), "\n"; |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub status { |
68
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
return { |
70
|
0
|
|
|
|
|
|
last_flush => $self->since($self->{lastFlush}), |
71
|
|
|
|
|
|
|
last_exception => $self->since($self->{lastException}), |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |