| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
13
|
|
|
13
|
|
73
|
use strict; |
|
|
13
|
|
|
|
|
24
|
|
|
|
13
|
|
|
|
|
565
|
|
|
2
|
13
|
|
|
13
|
|
78
|
use warnings; |
|
|
13
|
|
|
|
|
21
|
|
|
|
13
|
|
|
|
|
887
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Monitor::MetricsAPI::Metric::Counter; |
|
5
|
|
|
|
|
|
|
$Monitor::MetricsAPI::Metric::Counter::VERSION = '0.900'; |
|
6
|
13
|
|
|
13
|
|
74
|
use namespace::autoclean; |
|
|
13
|
|
|
|
|
19
|
|
|
|
13
|
|
|
|
|
115
|
|
|
7
|
13
|
|
|
13
|
|
998
|
use Moose; |
|
|
13
|
|
|
|
|
24
|
|
|
|
13
|
|
|
|
|
97
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Monitor::MetricsAPI::Metric'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Monitor::MetricsAPI::Metric::Counter - Counter metric class for Monitor::MetricsAPI |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Monitor::MetricsAPI; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $collector = Monitor::MetricsAPI->new( |
|
20
|
|
|
|
|
|
|
metrics => { messages => { incoming => 'counter' } } |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Later on, when a new message is received by your app: |
|
24
|
|
|
|
|
|
|
$collector->metric('messages/incoming')->increment; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Counter metrics are numeric values which initialize at zero and only increase |
|
29
|
|
|
|
|
|
|
over the lifetime of the monitored process. Counter metrics are appropriate |
|
30
|
|
|
|
|
|
|
when you simply want to know how many times I<X> occurred. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub BUILD { |
|
35
|
6
|
|
|
6
|
0
|
10
|
my ($self) = @_; |
|
36
|
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
230
|
$self->_set_value(0); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The following methods are specific to counter metrics. L<Monitor::MetricsAPI::Metric> |
|
43
|
|
|
|
|
|
|
defines methods which are common to all metric types. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 add ($amount) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Adds $amount to the current value of the metric. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub add { |
|
52
|
2
|
|
|
2
|
1
|
3
|
my ($self, $amount) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
2
|
50
|
|
|
|
65
|
return $self->_set_value(($self->_has_value ? $self->value : 0) + $amount); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 increment |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Increases the value of the metric by 1 each time it is called. Produces the |
|
60
|
|
|
|
|
|
|
same effect as calling $metric->add(1), which is unsurprising since that is exactly |
|
61
|
|
|
|
|
|
|
what this method does. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub increment { |
|
66
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
4
|
return $self->add(1); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 incr |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Alias for increment() |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub incr { |
|
78
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $self->add(1); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHORS |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Jon Sime <jonsime@gmail.com> |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This software is copyright (c) 2015 by OmniTI Computer Consulting, Inc. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
|
92
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. See L<perlartistic>. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
95
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
96
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
101
|
|
|
|
|
|
|
1; |