line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Netdata::Collector; |
2
|
2
|
|
|
2
|
|
231197
|
use Mojo::Base 'Mojo::EventEmitter', -signatures; |
|
2
|
|
|
|
|
163730
|
|
|
2
|
|
|
|
|
18
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
7391
|
use Carp qw(croak); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
90
|
|
5
|
2
|
|
|
2
|
|
885
|
use Mojo::Netdata::Chart; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
18
|
|
6
|
2
|
|
|
2
|
|
98
|
use Mojo::Netdata::Util qw(logf safe_id); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
120
|
|
7
|
2
|
|
|
2
|
|
2902
|
use Mojo::Promise; |
|
2
|
|
|
|
|
211826
|
|
|
2
|
|
|
|
|
14
|
|
8
|
2
|
|
|
2
|
|
98
|
use Time::HiRes qw(time); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has charts => sub ($self) { +{} }; |
11
|
|
|
|
|
|
|
has module => sub ($self) { lc(ref $self) =~ s!\W+!_!gr }; |
12
|
|
|
|
|
|
|
has type => sub ($self) { croak '"type" cannot be built' }; |
13
|
|
|
|
|
|
|
has update_every => 1; |
14
|
|
|
|
|
|
|
|
15
|
23
|
|
|
23
|
1
|
14556
|
sub chart ($self, $id) { |
|
23
|
|
|
|
|
41
|
|
|
23
|
|
|
|
|
55
|
|
|
23
|
|
|
|
|
30
|
|
16
|
23
|
|
|
|
|
67
|
my $key = safe_id $id; |
17
|
23
|
|
66
|
|
|
68
|
return $self->charts->{$key} //= Mojo::Netdata::Chart->new( |
18
|
|
|
|
|
|
|
module => $self->module, |
19
|
|
|
|
|
|
|
id => $id, |
20
|
|
|
|
|
|
|
type => $self->type, |
21
|
|
|
|
|
|
|
update_every => $self->update_every, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
1
|
2003
|
sub recurring_update_p ($self) { |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
8
|
|
26
|
3
|
|
|
|
|
27
|
my $next_time = time + $self->update_every; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->{recurring_update_p} //= $self->update_p->then(sub { |
29
|
2
|
|
|
2
|
|
1265
|
$self->emit_data; |
30
|
2
|
|
|
|
|
60
|
logf(debug => 'Will update in %0.3fs...', $next_time - time); |
31
|
2
|
|
|
|
|
15
|
return Mojo::Promise->timer($next_time - time); |
32
|
|
|
|
|
|
|
})->then(sub { |
33
|
2
|
|
|
2
|
|
402138
|
delete $self->{recurring_update_p}; |
34
|
2
|
|
|
|
|
21
|
return $self->recurring_update_p; |
35
|
3
|
|
33
|
|
|
52
|
}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
1
|
535
|
sub register ($self, $config, $netdata) { } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
39
|
1
|
|
|
1
|
1
|
2
|
sub update_p ($self) { Mojo::Promise->resolve } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
4
|
1
|
2403
|
sub emit_data ($self) { |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
7
|
|
42
|
4
|
|
|
|
|
11
|
my @stdout = map { $self->charts->{$_}->data_to_string } sort keys %{$self->charts}; |
|
1
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
15
|
|
43
|
4
|
|
|
|
|
48
|
return $self->emit(stdout => join '', @stdout); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
2
|
1
|
4077
|
sub emit_charts ($self) { |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
4
|
|
47
|
2
|
|
|
|
|
3
|
my @stdout = map { $self->charts->{$_}->to_string } sort keys %{$self->charts}; |
|
1
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
7
|
|
48
|
2
|
|
|
|
|
15
|
return $self->emit(stdout => join '', @stdout); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding utf8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Mojo::Netdata::Collector - Base class for Mojo::Netdata collectors |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Mojo::Netdata::Collector::CoolBeans; |
62
|
|
|
|
|
|
|
use Mojo::Base 'Mojo::Netdata::Collector', -signatures; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has type => 'ice_cool'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub register ($self, $config, $netdata) { ... } |
67
|
|
|
|
|
|
|
sub update_p ($self) { ... } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L has basic functionality which should be inherited |
74
|
|
|
|
|
|
|
by L collectors. See L for an |
75
|
|
|
|
|
|
|
(example) implementation. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 charts |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$hash_ref = $collector->charts; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 module |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$str = $collector->module; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Defaults to a decamelized version of L<$collector>. This is used as default |
88
|
|
|
|
|
|
|
value for L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 type |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$str = $collector->type; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This value must be set. This is used as default value for |
95
|
|
|
|
|
|
|
L. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 update_every |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$num = $chart->update_every; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Used by L to figure out how often to update Netdata. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 METHODS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 chart |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$chart = $collector->chart($id); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns a L object identified by L. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 emit_charts |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$collector = $collector->emit_charts; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Emits all the L specifications as an "stdout" event. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 emit_data |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$collector = $collector->emit_data; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Emits all the L data as an "stdout" event. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 recurring_update_p |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$p = $collector->recurring_update_p; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Calls L on L interval, until the process is killed. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 register |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$collector = $collector->register(\%config, $netdata); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Called by L when initialized, and should return C<$collector> on |
134
|
|
|
|
|
|
|
success or C if the collector should I be registered. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 update_p |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$p = $collector->update_p; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Must be defined in the sub class. This method should update |
141
|
|
|
|
|
|
|
L. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SEE ALSO |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |