| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
|
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2020 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package IO::Async::Metrics; |
|
7
|
|
|
|
|
|
|
|
|
8
|
102
|
|
|
102
|
|
597
|
use strict; |
|
|
102
|
|
|
|
|
176
|
|
|
|
102
|
|
|
|
|
2539
|
|
|
9
|
102
|
|
|
102
|
|
428
|
use warnings; |
|
|
102
|
|
|
|
|
135
|
|
|
|
102
|
|
|
|
|
11752
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Metrics support is entirely optional |
|
12
|
|
|
|
|
|
|
our $METRICS; |
|
13
|
|
|
|
|
|
|
eval { |
|
14
|
|
|
|
|
|
|
require Metrics::Any and |
|
15
|
|
|
|
|
|
|
Metrics::Any->VERSION( '0.05' ) and |
|
16
|
|
|
|
|
|
|
Metrics::Any->import( '$METRICS', |
|
17
|
|
|
|
|
|
|
name_prefix => [qw( io_async )], |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
C - report metrics about C to C |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module contains the implementation of metrics-reporting code from |
|
28
|
|
|
|
|
|
|
C to provide information about its operation into L. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
163
|
|
|
163
|
|
371
|
my $class = shift; |
|
35
|
163
|
|
|
|
|
349
|
my $caller = caller; |
|
36
|
163
|
|
|
|
|
369
|
my ( $varname ) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
163
|
|
|
|
|
744
|
$varname =~ s/^\$//; |
|
39
|
|
|
|
|
|
|
|
|
40
|
102
|
|
|
102
|
|
846
|
no strict 'refs'; |
|
|
102
|
|
|
|
|
225
|
|
|
|
102
|
|
|
|
|
21720
|
|
|
41
|
163
|
|
|
|
|
358
|
*{"${caller}::${varname}"} = \$METRICS; |
|
|
163
|
|
|
|
|
5888
|
|
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METRICS |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The following metrics are reported: |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 io_async_forks |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
A counter giving the number of times that C has been called by the |
|
51
|
|
|
|
|
|
|
L. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 io_async_notifiers |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
A gauge giving the number of L currently registered |
|
56
|
|
|
|
|
|
|
with the Loop. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 io_async_processing |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A time distribution giving the amount of time spent processing IO events. This |
|
61
|
|
|
|
|
|
|
time does not include the time spent blocking on the underlying kernel system |
|
62
|
|
|
|
|
|
|
call to wait for IO events, but only the time spent in userland afterwards to |
|
63
|
|
|
|
|
|
|
handle them. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 io_async_resolver_lookups |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A labelled counter giving the number of attempted lookups by the |
|
68
|
|
|
|
|
|
|
L. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This metric has one label, C, containing the type of lookup; |
|
71
|
|
|
|
|
|
|
e.g. C. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 io_async_resolver_failures |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
A labelled counter giving the number of Resolver lookups that failed. This is |
|
76
|
|
|
|
|
|
|
labelled as for C. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 io_async_stream_read |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
A counter giving the number of bytes read by L instances. |
|
81
|
|
|
|
|
|
|
Note that for SSL connections, this will only be able to count bytes of |
|
82
|
|
|
|
|
|
|
plaintext, not ciphertext, and thus will be a slight under-estimate in this |
|
83
|
|
|
|
|
|
|
case. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 io_async_stream_written |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
A counter giving the number of bytes written by Stream instances. Note again |
|
88
|
|
|
|
|
|
|
for SSL connections this will only be able to count bytes of plaintext. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if( defined $METRICS ) { |
|
93
|
|
|
|
|
|
|
# Loop metrics |
|
94
|
|
|
|
|
|
|
$METRICS->make_gauge( notifiers => |
|
95
|
|
|
|
|
|
|
description => "Number of IO::Async::Notifiers registered with the Loop", |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
$METRICS->make_counter( forks => |
|
98
|
|
|
|
|
|
|
description => "Number of times IO::Async has fork()ed a process", |
|
99
|
|
|
|
|
|
|
); |
|
100
|
|
|
|
|
|
|
$METRICS->make_timer( processing_time => |
|
101
|
|
|
|
|
|
|
name => [qw( processing )], |
|
102
|
|
|
|
|
|
|
description => "Time spent by IO::Async:Loop processing IO", |
|
103
|
|
|
|
|
|
|
# Override bucket generation |
|
104
|
|
|
|
|
|
|
bucket_min => 0.001, bucket_max => 1, # 1msec to 1sec |
|
105
|
|
|
|
|
|
|
buckets_per_decade => [qw( 1 2.5 5 )], |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
$METRICS->make_gauge( loops => |
|
108
|
|
|
|
|
|
|
description => "Count of IO::Async::Loop instances by class", |
|
109
|
|
|
|
|
|
|
labels => [qw( class )], |
|
110
|
|
|
|
|
|
|
); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Resolver metrics |
|
113
|
|
|
|
|
|
|
$METRICS->make_counter( resolver_lookups => |
|
114
|
|
|
|
|
|
|
name => [qw( resolver lookups )], |
|
115
|
|
|
|
|
|
|
description => "Number of IO::Async::Resolver lookups by type", |
|
116
|
|
|
|
|
|
|
labels => [qw( type )], |
|
117
|
|
|
|
|
|
|
); |
|
118
|
|
|
|
|
|
|
$METRICS->make_counter( resolver_failures => |
|
119
|
|
|
|
|
|
|
name => [qw( resolver failures )], |
|
120
|
|
|
|
|
|
|
description => "Number of IO::Async::Resolver lookups that failed by type", |
|
121
|
|
|
|
|
|
|
labels => [qw( type )], |
|
122
|
|
|
|
|
|
|
); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Stream metrics |
|
125
|
|
|
|
|
|
|
$METRICS->make_counter( stream_written => |
|
126
|
|
|
|
|
|
|
name => [qw( stream written )], |
|
127
|
|
|
|
|
|
|
description => "Bytes written by IO::Async::Streams", |
|
128
|
|
|
|
|
|
|
units => "bytes", |
|
129
|
|
|
|
|
|
|
); |
|
130
|
|
|
|
|
|
|
$METRICS->make_counter( stream_read => |
|
131
|
|
|
|
|
|
|
name => [qw( stream read )], |
|
132
|
|
|
|
|
|
|
description => "Bytes read by IO::Async::Streams", |
|
133
|
|
|
|
|
|
|
units => "bytes", |
|
134
|
|
|
|
|
|
|
); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Paul Evans |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
0x55AA; |