line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Statsd::Client; |
2
|
3
|
|
|
3
|
|
4364
|
use Moo; |
|
3
|
|
|
|
|
36385
|
|
|
3
|
|
|
|
|
19
|
|
3
|
3
|
|
|
3
|
|
6149
|
use Sub::Quote; |
|
3
|
|
|
|
|
14779
|
|
|
3
|
|
|
|
|
264
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Send data to StatsD / Graphite |
6
|
|
|
|
|
|
|
our $VERSION = '0.33'; # VERSION |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1493
|
use Etsy::StatsD 1.001; |
|
3
|
|
|
|
|
70838
|
|
|
3
|
|
|
|
|
140
|
|
10
|
3
|
|
|
3
|
|
1963
|
use Net::Statsd::Client::Timer; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
2266
|
|
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
|
16940
|
my ($self) = @_; |
42
|
4
|
|
|
|
|
97
|
$self->statsd( |
43
|
|
|
|
|
|
|
Etsy::StatsD->new($self->host, $self->port) |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub increment { |
48
|
2
|
|
|
2
|
1
|
2092
|
my ($self, $metric, $sample_rate) = @_; |
49
|
2
|
|
|
|
|
10
|
$metric = "$self->{prefix}$metric"; |
50
|
2
|
50
|
|
|
|
15
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
51
|
2
|
|
|
|
|
15
|
$self->{statsd}->increment($metric, $sample_rate); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub decrement { |
55
|
2
|
|
|
2
|
1
|
2013
|
my ($self, $metric, $sample_rate) = @_; |
56
|
2
|
|
|
|
|
10
|
$metric = "$self->{prefix}$metric"; |
57
|
2
|
50
|
|
|
|
12
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
58
|
2
|
|
|
|
|
32
|
$self->{statsd}->decrement($metric, $sample_rate); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub update { |
62
|
2
|
|
|
2
|
1
|
1774
|
my ($self, $metric, $value, $sample_rate) = @_; |
63
|
2
|
|
|
|
|
9
|
$metric = "$self->{prefix}$metric"; |
64
|
2
|
50
|
|
|
|
12
|
$sample_rate = $self->{sample_rate} unless defined $sample_rate; |
65
|
2
|
|
|
|
|
25
|
$self->{statsd}->update($metric, $value, $sample_rate); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub timing_ms { |
69
|
7
|
|
|
7
|
1
|
1881
|
my ($self, $metric, $time, $sample_rate) = @_; |
70
|
7
|
|
|
|
|
35
|
$metric = "$self->{prefix}$metric"; |
71
|
7
|
|
|
|
|
66
|
$self->{statsd}->timing($metric, $time, $sample_rate); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub gauge { |
75
|
1
|
|
|
1
|
1
|
950
|
my ($self, $metric, $value, $sample_rate) = @_; |
76
|
1
|
|
|
|
|
4
|
$metric = "$self->{prefix}$metric"; |
77
|
1
|
|
|
|
|
8
|
$self->{statsd}->send({ $metric => "$value|g" }, $sample_rate); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub set_add { |
81
|
1
|
|
|
1
|
1
|
653
|
my ($self, $metric, $value, $sample_rate) = @_; |
82
|
1
|
|
|
|
|
3
|
$metric = "$self->{prefix}$metric"; |
83
|
1
|
|
|
|
|
9
|
$self->{statsd}->send({ $metric => "$value|s" }, $sample_rate); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub timer { |
87
|
6
|
|
|
6
|
1
|
6098
|
my ($self, $metric, $sample_rate) = @_; |
88
|
|
|
|
|
|
|
|
89
|
6
|
|
|
|
|
157
|
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__ |