line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Netdata::Collector; |
2
|
2
|
|
|
2
|
|
186797
|
use Mojo::Base 'Mojo::EventEmitter', -signatures; |
|
2
|
|
|
|
|
134224
|
|
|
2
|
|
|
|
|
16
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
6391
|
use Carp qw(croak); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
80
|
|
5
|
2
|
|
|
2
|
|
770
|
use Mojo::Netdata::Chart; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
6
|
2
|
|
|
2
|
|
76
|
use Mojo::Netdata::Util qw(logf safe_id); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
7
|
2
|
|
|
2
|
|
1757
|
use Mojo::Promise; |
|
2
|
|
|
|
|
214598
|
|
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
80
|
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
|
11922
|
sub chart ($self, $id) { |
|
29
|
|
|
|
|
34
|
|
|
29
|
|
|
|
|
36
|
|
|
29
|
|
|
|
|
33
|
|
16
|
29
|
|
|
|
|
111
|
my $key = safe_id $id; |
17
|
29
|
|
66
|
|
|
69
|
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
|
1752
|
sub recurring_update_p ($self) { |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
5
|
|
26
|
3
|
|
|
|
|
16
|
my $next_time = time + $self->update_every; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->{recurring_update_p} //= $self->update_p->then(sub { |
29
|
2
|
|
|
2
|
|
802
|
$self->emit_data; |
30
|
2
|
|
|
|
|
41
|
logf(debug => 'Will update in %0.3fs...', $next_time - time); |
31
|
2
|
|
|
|
|
10
|
return Mojo::Promise->timer($next_time - time); |
32
|
|
|
|
|
|
|
})->then(sub { |
33
|
2
|
|
|
2
|
|
401914
|
delete $self->{recurring_update_p}; |
34
|
2
|
|
|
|
|
12
|
return $self->recurring_update_p; |
35
|
3
|
|
33
|
|
|
34
|
}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
1
|
450
|
sub register ($self, $config, $netdata) { } |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
39
|
1
|
|
|
1
|
1
|
2
|
sub update_p ($self) { Mojo::Promise->resolve } |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
5
|
1
|
2795
|
sub emit_data ($self) { |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
9
|
|
42
|
5
|
|
|
|
|
9
|
my @stdout = map { $self->charts->{$_}->data_to_string } sort keys %{$self->charts}; |
|
5
|
|
|
|
|
31
|
|
|
5
|
|
|
|
|
18
|
|
43
|
5
|
|
|
|
|
49
|
return $self->emit(stdout => join '', @stdout); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
3
|
1
|
4949
|
sub emit_charts ($self) { |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
6
|
|
47
|
3
|
|
|
|
|
5
|
my @stdout = map { $self->charts->{$_}->to_string } sort keys %{$self->charts}; |
|
5
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
9
|
|
48
|
3
|
|
|
|
|
26
|
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 |