| 1 | package Net::Statsd::Client; | ||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use Sub::Quote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | # ABSTRACT: Send data to StatsD / Graphite | ||||||||||
| 6 | 3 | our $VERSION = '0.34'; # VERSION | |||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY | |||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use Etsy::StatsD 1.001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Net::Statsd::Client::Timer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | has 'prefix' => ( | |||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | default => quote_sub q{''}, | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 3 | has 'sample_rate' => ( | |||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | default => quote_sub q{1}, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 3 | has 'host' => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | default => quote_sub q{'localhost'}, | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | 3 | has 'port' => ( | |||||||||
| 28 | is => 'ro', | ||||||||||
| 29 | default => quote_sub q{8125}, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 3 | has 'statsd' => ( | |||||||||
| 33 | is => 'rw', | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | 3 | has 'warning_callback' => ( | |||||||||
| 37 | is => 'rw', | ||||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | 4 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 41 | 4 | my ($self) = @_; | |||||||||
| 42 | 4 | $self->statsd( | |||||||||
| 43 | Etsy::StatsD->new($self->host, $self->port) | ||||||||||
| 44 | ); | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 2 | ▶ | sub increment { | ||||||||
|
Subroutine
increment: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 48 | 2 | my ($self, $metric, $sample_rate) = @_; | |||||||||
| 49 | 2 | $metric = "$self->{prefix}$metric"; | |||||||||
| 50 | 2 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 2 | $self->{statsd}->increment($metric, $sample_rate); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 2 | ▶ | sub decrement { | ||||||||
|
Subroutine
decrement: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 55 | 2 | my ($self, $metric, $sample_rate) = @_; | |||||||||
| 56 | 2 | $metric = "$self->{prefix}$metric"; | |||||||||
| 57 | 2 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 2 | $self->{statsd}->decrement($metric, $sample_rate); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 2 | ▶ | sub update { | ||||||||
|
Subroutine
update: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 62 | 2 | my ($self, $metric, $value, $sample_rate) = @_; | |||||||||
| 63 | 2 | $metric = "$self->{prefix}$metric"; | |||||||||
| 64 | 2 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 2 | $self->{statsd}->update($metric, $value, $sample_rate); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 7 | ▶ | sub timing_ms { | ||||||||
|
Subroutine
timing_ms: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 7 | my ($self, $metric, $time, $sample_rate) = @_; | |||||||||
| 70 | 7 | $metric = "$self->{prefix}$metric"; | |||||||||
| 71 | 7 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 7 | $self->{statsd}->timing($metric, $time, $sample_rate); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | sub gauge { | ||||||||
|
Subroutine
gauge: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 76 | 1 | my ($self, $metric, $value, $sample_rate) = @_; | |||||||||
| 77 | 1 | $metric = "$self->{prefix}$metric"; | |||||||||
| 78 | 1 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 1 | $self->{statsd}->send({ $metric => "$value|g" }, $sample_rate); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | sub set_add { | ||||||||
|
Subroutine
set_add: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 83 | 1 | my ($self, $metric, $value, $sample_rate) = @_; | |||||||||
| 84 | 1 | $metric = "$self->{prefix}$metric"; | |||||||||
| 85 | 1 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 1 | $self->{statsd}->send({ $metric => "$value|s" }, $sample_rate); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 6 | ▶ | sub timer { | ||||||||
|
Subroutine
timer: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 90 | 6 | my ($self, $metric, $sample_rate) = @_; | |||||||||
| 91 | 6 | ▶ | $sample_rate = $self->{sample_rate} unless defined $sample_rate; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | |||||||||||
| 93 | 6 | return Net::Statsd::Client::Timer->new( | |||||||||
| 94 | statsd => $self, | ||||||||||
| 95 | metric => $metric, | ||||||||||
| 96 | sample_rate => $sample_rate, | ||||||||||
| 97 | warning_callback => $self->warning_callback, | ||||||||||
| 98 | ); | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 3 | 1; | |||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||