| 1 | # ABSTRACT: Console backend for Net::Statsd::Server | ||
| 2 | |||
| 3 | package Net::Statsd::Server::Backend::Console; | ||
| 4 | 1 | $Net::Statsd::Server::Backend::Console::VERSION = '0.20'; | |
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use JSON::XS (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | ▶ | use base qw(Net::Statsd::Server::Backend); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 0 | ▶ | sub init { |
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 12 | 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 | 0 | ▶ | sub flush { |
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 30 | 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 | 0 | ▶ | sub status { |
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 65 | 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 | 1; | |