| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojo::Netdata; |
|
2
|
2
|
|
|
2
|
|
462061
|
use Mojo::Base -base, -signatures; |
|
|
2
|
|
|
|
|
324305
|
|
|
|
2
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
8229
|
use IO::Handle; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
87
|
|
|
5
|
2
|
|
|
2
|
|
1000
|
use Mojo::File qw(path); |
|
|
2
|
|
|
|
|
63570
|
|
|
|
2
|
|
|
|
|
135
|
|
|
6
|
2
|
|
|
2
|
|
888
|
use Mojo::Netdata::Util qw(logf); |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
3076
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has collectors => sub ($self) { $self->_build_collectors }; |
|
11
|
|
|
|
|
|
|
has config => sub ($self) { $self->_build_config }; |
|
12
|
|
|
|
|
|
|
has user_config_dir => sub ($self) { $ENV{NETDATA_USER_CONFIG_DIR} || '/etc/netdata' }; |
|
13
|
|
|
|
|
|
|
has stock_config_dir => sub ($self) { $ENV{NETDATA_STOCK_CONFIG_DIR} || '/usr/lib/netdata/conf.d' }; |
|
14
|
|
|
|
|
|
|
has plugins_dir => sub ($self) { $ENV{NETDATA_PLUGINS_DIR} || '' }; |
|
15
|
|
|
|
|
|
|
has web_dir => sub ($self) { $ENV{NETDATA_WEB_DIR} || '' }; |
|
16
|
|
|
|
|
|
|
has cache_dir => sub ($self) { $ENV{NETDATA_CACHE_DIR} || '' }; |
|
17
|
|
|
|
|
|
|
has log_dir => sub ($self) { $ENV{NETDATA_LOG_DIR} || '' }; |
|
18
|
|
|
|
|
|
|
has host_prefix => sub ($self) { $ENV{NETDATA_HOST_PREFIX} || '' }; |
|
19
|
|
|
|
|
|
|
has debug_flags => sub ($self) { $ENV{NETDATA_DEBUG_FLAGS} || '' }; |
|
20
|
|
|
|
|
|
|
has update_every => sub ($self) { $ENV{NETDATA_UPDATE_EVERY} || 1 }; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
1
|
0
|
sub start ($self) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
23
|
|
|
|
|
|
|
logf( |
|
24
|
|
|
|
|
|
|
info => 'Starting %s with debug_flags=%s host_prefix=%s update_every=%s', |
|
25
|
0
|
|
|
|
|
0
|
ref($self), map { $self->$_ } qw(debug_flags host_prefix update_every), |
|
|
0
|
|
|
|
|
0
|
|
|
26
|
|
|
|
|
|
|
); |
|
27
|
0
|
0
|
|
|
|
0
|
return 0 unless @{$self->collectors}; |
|
|
0
|
|
|
|
|
0
|
|
|
28
|
0
|
|
|
|
|
0
|
$_->emit_charts->recurring_update_p for @{$self->collectors}; |
|
|
0
|
|
|
|
|
0
|
|
|
29
|
0
|
|
|
|
|
0
|
return int @{$self->collectors}; |
|
|
0
|
|
|
|
|
0
|
|
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
2
|
|
|
2
|
|
3
|
sub _build_config ($self) { |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2
|
|
|
33
|
2
|
|
|
|
|
4
|
my $config = {}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
6
|
my $file = path($self->user_config_dir, 'mojo.conf.pl')->to_abs; |
|
36
|
2
|
100
|
|
|
|
112
|
if (-r $file) { |
|
37
|
1
|
|
|
|
|
43
|
logf(debug => 'Loading config file %s into config().', $file); |
|
38
|
1
|
|
|
|
|
4
|
$config = _eval_file($file); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
44
|
my $conf_d = path($self->user_config_dir, 'mojo.conf.d')->to_abs->list->sort; |
|
42
|
2
|
|
|
|
|
456
|
for my $file ($conf_d->each) { |
|
43
|
3
|
100
|
|
|
|
59
|
next unless $file->basename =~ m!\.conf\.pl$!; |
|
44
|
2
|
50
|
|
|
|
90
|
next unless my $d = _eval_file($file); |
|
45
|
|
|
|
|
|
|
|
|
46
|
2
|
100
|
|
|
|
17
|
if ($d->{collector}) { |
|
47
|
1
|
|
|
|
|
7
|
logf(debug => 'Adding config file %s to "collectors".', $file); |
|
48
|
1
|
|
|
|
|
1
|
push @{$config->{collectors}}, $d; |
|
|
1
|
|
|
|
|
5
|
|
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
1
|
|
|
|
|
6
|
logf(debug => 'Merging config file %s into config().', $file); |
|
52
|
1
|
|
|
|
|
7
|
@$config{keys(%$d)} = values %$d; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
25
|
return $config; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
1
|
|
2
|
sub _build_collectors ($self) { |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
60
|
1
|
|
50
|
|
|
8
|
my $fh = $self->{stdout} // \*STDOUT; # for testing |
|
61
|
1
|
|
|
|
|
10
|
$fh->autoflush; |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
54
|
local $@; |
|
64
|
1
|
|
|
|
|
2
|
my @collectors; |
|
65
|
1
|
50
|
|
|
|
37
|
for my $collector_config (@{$self->config->{collectors} || []}) { |
|
|
1
|
|
|
|
|
6
|
|
|
66
|
2
|
|
|
|
|
14
|
my $collector_class = $collector_config->{collector}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
21
|
unless ($collector_class and $collector_class =~ m!^[\w:]+$!) { |
|
69
|
0
|
|
0
|
|
|
0
|
logf(error => 'Invalid collector_class %s', $collector_class || 'missing'); |
|
70
|
0
|
|
|
|
|
0
|
next; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
2
|
50
|
|
|
|
173
|
unless (eval "require $collector_class;1") { |
|
73
|
0
|
|
|
|
|
0
|
logf(error => 'Load %s FAIL %s', $collector_class, $@); |
|
74
|
0
|
|
|
|
|
0
|
next; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
50
|
|
|
|
17
|
next unless my $collector = $collector_class->new->register($collector_config, $self); |
|
78
|
2
|
|
|
0
|
|
37
|
$collector->on(stdout => sub ($collector, $str) { $fh->print($str) }); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
79
|
2
|
|
|
|
|
23
|
logf(debug => 'Loaded and set up %s', $collector_class); |
|
80
|
2
|
|
|
|
|
6
|
push @collectors, $collector; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
6
|
return \@collectors; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
3
|
|
|
3
|
|
5
|
sub _eval_file ($file) { |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
5
|
|
|
87
|
3
|
|
|
|
|
5
|
local $@; |
|
88
|
3
|
|
|
|
|
5
|
my $prefix = 'package Mojo::Netdata::Config; no warnings; use Mojo::Base -strict;'; |
|
89
|
3
|
|
|
1
|
|
12
|
my $config = eval $prefix . $file->slurp; |
|
|
1
|
|
|
1
|
|
304
|
|
|
|
1
|
|
|
1
|
|
1
|
|
|
|
1
|
|
|
1
|
|
48
|
|
|
|
1
|
|
|
1
|
|
6
|
|
|
|
1
|
|
|
1
|
|
1
|
|
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
239
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
196
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
49
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
90
|
3
|
50
|
|
|
|
22
|
logf(error => 'Config file "%s" is invalid: %s', $file, $@) if $@; |
|
91
|
3
|
|
|
|
|
13
|
return $config; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding utf8 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Mojo::Netdata - https://netdata.cloud plugin for Perl |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 Installation |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sudo -i |
|
107
|
|
|
|
|
|
|
apt install -y cpanminus |
|
108
|
|
|
|
|
|
|
cpanm -n https://github.com/jhthorsen/mojo-netdata/archive/refs/heads/main.tar.gz |
|
109
|
|
|
|
|
|
|
ln -s $(which mojo-netdata) /etc/netdata/custom-plugins.d/mojo-netdata.plugin |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# See "Config file" below for information on what to place inside mojo.conf.pl |
|
112
|
|
|
|
|
|
|
$EDITOR /etc/netdata/mojo.conf.pl |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Config files |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The config files are located in C. The files are |
|
117
|
|
|
|
|
|
|
plain Perl files, which means you can define variables and call functions. The |
|
118
|
|
|
|
|
|
|
only important part is that the last statement in the file is a hash-ref. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Any hash-refs that has the "collector" key will be placed into L, |
|
121
|
|
|
|
|
|
|
while everything else will be merged into L. Example: |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# /etc/netdata/mojo.conf.d/foo.conf.pl |
|
124
|
|
|
|
|
|
|
{foo => 42, bar => 100} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# /etc/netdata/mojo.conf.d/bar.conf.pl |
|
127
|
|
|
|
|
|
|
{collector => 'Mojo::Netdata::Collector::HTTP', jobs => []} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The two config files above will result in this L: |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
{ |
|
132
|
|
|
|
|
|
|
foo => 42, |
|
133
|
|
|
|
|
|
|
bar => 100, |
|
134
|
|
|
|
|
|
|
collectors => [ |
|
135
|
|
|
|
|
|
|
{collector => 'Mojo::Netdata::Collector::HTTP', jobs => []}, |
|
136
|
|
|
|
|
|
|
}, |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
See L for an example config file. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 Log file |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The output from this Netdata plugin can be found in |
|
144
|
|
|
|
|
|
|
C. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L is a plugin for L. It can load |
|
149
|
|
|
|
|
|
|
custom L classes and write data back to Netdata on a |
|
150
|
|
|
|
|
|
|
given interval. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This module is currently EXPERIMENTAL, and the API might change without |
|
153
|
|
|
|
|
|
|
warning. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 cache_dir |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$path = $netdata->cache_dir; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
162
|
|
|
|
|
|
|
L |
|
163
|
|
|
|
|
|
|
for more details. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 config |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$hash_ref = $netdata->config; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Holds the config for L and all L. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 collectors |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$array_ref = $netdata->collectors; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
An array-ref of L objects. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 debug_flags |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$str = $netdata->debug_flags; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Defaults to the C environment variable. See |
|
182
|
|
|
|
|
|
|
L |
|
183
|
|
|
|
|
|
|
for more details. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 host_prefix |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$str = $netdata->host_prefix; |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Defaults to the C environment variable. See |
|
190
|
|
|
|
|
|
|
L |
|
191
|
|
|
|
|
|
|
for more details. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 log_dir |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$path = $netdata->log_dir; |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
198
|
|
|
|
|
|
|
L |
|
199
|
|
|
|
|
|
|
for more details. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 plugins_dir |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
$path = $netdata->plugins_dir; |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
206
|
|
|
|
|
|
|
L |
|
207
|
|
|
|
|
|
|
for more details. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 stock_config_dir |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
$path = $netdata->stock_config_dir; |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
214
|
|
|
|
|
|
|
L |
|
215
|
|
|
|
|
|
|
for more details. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 update_every |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
$num = $netdata->update_every; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Defaults to the C environment variable. See |
|
222
|
|
|
|
|
|
|
L |
|
223
|
|
|
|
|
|
|
for more details. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 user_config_dir |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
$path = $netdata->user_config_dir; |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
230
|
|
|
|
|
|
|
L |
|
231
|
|
|
|
|
|
|
for more details. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 web_dir |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
$path = $netdata->web_dir; |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Holds the C environment variable. See |
|
238
|
|
|
|
|
|
|
L |
|
239
|
|
|
|
|
|
|
for more details. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 METHODS |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 start |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$bool = $netdata->start; |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Reads the L and return 1 if any L got registered. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 AUTHOR |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Jan Henning Thorsen |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Copyright (C) Jan Henning Thorsen |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
|
258
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L. |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |