line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Netdata::Collector; |
2
|
2
|
|
|
2
|
|
220748
|
use Mojo::Base 'Mojo::EventEmitter', -signatures; |
|
2
|
|
|
|
|
144094
|
|
|
2
|
|
|
|
|
16
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
6287
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
5
|
2
|
|
|
2
|
|
772
|
use Mojo::Netdata::Chart; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
6
|
2
|
|
|
2
|
|
67
|
use Mojo::Netdata::Util qw(logf safe_id); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
7
|
2
|
|
|
2
|
|
890
|
use Mojo::Promise; |
|
2
|
|
|
|
|
290887
|
|
|
2
|
|
|
|
|
20
|
|
8
|
2
|
|
|
2
|
|
91
|
use Time::HiRes qw(time); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
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
|
29
|
|
|
29
|
1
|
13492
|
sub chart ($self, $id) { |
|
29
|
|
|
|
|
63
|
|
|
29
|
|
|
|
|
40
|
|
|
29
|
|
|
|
|
35
|
|
16
|
29
|
|
|
|
|
80
|
my $key = safe_id $id; |
17
|
29
|
|
66
|
|
|
102
|
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
|
1621
|
sub recurring_update_p ($self) { |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
9
|
|
26
|
3
|
|
|
|
|
23
|
my $next_time = time + $self->update_every; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->{recurring_update_p} //= $self->update_p->then(sub { |
29
|
2
|
|
|
2
|
|
1291
|
$self->emit_data; |
30
|
2
|
|
|
|
|
78
|
logf(debug => 'Will update in %0.3fs...', $next_time - time); |
31
|
2
|
|
|
|
|
29
|
return Mojo::Promise->timer($next_time - time); |
32
|
|
|
|
|
|
|
})->then(sub { |
33
|
2
|
|
|
2
|
|
402349
|
delete $self->{recurring_update_p}; |
34
|
2
|
|
|
|
|
19
|
return $self->recurring_update_p; |
35
|
3
|
|
33
|
|
|
56
|
}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
1
|
447
|
sub register ($self, $config, $netdata) { } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
39
|
1
|
|
|
1
|
1
|
2
|
sub update_p ($self) { Mojo::Promise->resolve } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
5
|
1
|
2493
|
sub emit_data ($self) { |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
8
|
|
42
|
5
|
|
|
|
|
13
|
my @stdout = map { $self->charts->{$_}->data_to_string } sort keys %{$self->charts}; |
|
5
|
|
|
|
|
31
|
|
|
5
|
|
|
|
|
17
|
|
43
|
5
|
|
|
|
|
98
|
return $self->emit(stdout => join '', @stdout); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
3
|
1
|
5362
|
sub emit_charts ($self) { |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
5
|
|
47
|
3
|
|
|
|
|
6
|
my @stdout = map { $self->charts->{$_}->to_string } sort keys %{$self->charts}; |
|
5
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
20
|
|
48
|
3
|
|
|
|
|
31
|
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 |