line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Statsd::Client; |
2
|
3
|
|
|
3
|
|
2471
|
use Moo; |
|
3
|
|
|
|
|
23036
|
|
|
3
|
|
|
|
|
13
|
|
3
|
3
|
|
|
3
|
|
3755
|
use Sub::Quote; |
|
3
|
|
|
|
|
10259
|
|
|
3
|
|
|
|
|
208
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Send data to StatsD / Graphite |
6
|
|
|
|
|
|
|
our $VERSION = '0.32'; # VERSION |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
714
|
use Etsy::StatsD 1.001; |
|
3
|
|
|
|
|
46686
|
|
|
3
|
|
|
|
|
83
|
|
10
|
3
|
|
|
3
|
|
900
|
use Net::Statsd::Client::Timer; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
1307
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'prefix' => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => quote_sub q{''}, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'sample_rate' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
default => quote_sub q{1}, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'host' => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => quote_sub q{'localhost'}, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'port' => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
default => quote_sub q{8125}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'statsd' => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'warning_callback' => ( |
37
|
|
|
|
|
|
|
is => 'rw', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub BUILD { |
41
|
4
|
|
|
4
|
0
|
10347
|
my ($self) = @_; |
42
|
4
|
|
|
|
|
72
|
$self->statsd( |
43
|
|
|
|
|
|
|
Etsy::StatsD->new($self->host, $self->port) |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub increment { |
48
|
2
|
|
|
2
|
1
|
1346
|
my ($self, $metric, $sample_rate) = @_; |
49
|
2
|
|
|
|
|
7
|
$metric = "$self->{prefix}$metric"; |
50
|
2
|
50
|
|
|
|
12
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
51
|
2
|
|
|
|
|
12
|
$self->{statsd}->increment($metric, $sample_rate); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub decrement { |
55
|
2
|
|
|
2
|
1
|
1534
|
my ($self, $metric, $sample_rate) = @_; |
56
|
2
|
|
|
|
|
7
|
$metric = "$self->{prefix}$metric"; |
57
|
2
|
50
|
|
|
|
10
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
58
|
2
|
|
|
|
|
25
|
$self->{statsd}->decrement($metric, $sample_rate); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub update { |
62
|
2
|
|
|
2
|
1
|
1499
|
my ($self, $metric, $value, $sample_rate) = @_; |
63
|
2
|
|
|
|
|
11
|
$metric = "$self->{prefix}$metric"; |
64
|
2
|
50
|
|
|
|
11
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
65
|
2
|
|
|
|
|
11
|
$self->{statsd}->update($metric, $value, $sample_rate); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub timing_ms { |
69
|
7
|
|
|
7
|
1
|
1680
|
my ($self, $metric, $time, $sample_rate) = @_; |
70
|
7
|
|
|
|
|
29
|
$metric = "$self->{prefix}$metric"; |
71
|
7
|
|
|
|
|
54
|
$self->{statsd}->timing($metric, $time, $sample_rate); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub gauge { |
75
|
1
|
|
|
1
|
1
|
1084
|
my ($self, $metric, $value, $sample_rate) = @_; |
76
|
1
|
|
|
|
|
6
|
$metric = "$self->{prefix}$metric"; |
77
|
1
|
|
|
|
|
11
|
$self->{statsd}->send({ $metric => "$value|g" }, $sample_rate); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub set_add { |
81
|
1
|
|
|
1
|
1
|
871
|
my ($self, $metric, $value, $sample_rate) = @_; |
82
|
1
|
|
|
|
|
5
|
$metric = "$self->{prefix}$metric"; |
83
|
1
|
|
|
|
|
8
|
$self->{statsd}->send({ $metric => "$value|s" }, $sample_rate); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub timer { |
87
|
6
|
|
|
6
|
1
|
4132
|
my ($self, $metric, $sample_rate) = @_; |
88
|
|
|
|
|
|
|
|
89
|
6
|
|
|
|
|
114
|
return Net::Statsd::Client::Timer->new( |
90
|
|
|
|
|
|
|
statsd => $self, |
91
|
|
|
|
|
|
|
metric => $metric, |
92
|
|
|
|
|
|
|
sample_rate => $sample_rate, |
93
|
|
|
|
|
|
|
warning_callback => $self->warning_callback, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |