logging now also logs the thread tag, so that all logs state their source process within netdata
Costa Tsaousis (ktsaou) committed
Dec 28, 2017 at 13:43 UTC
23c2ab2f277ff6de68bab98f0be42b0dbe48e89a
8 files changed
+107
-83
src/log.c
+7
-7
@@ -246,7 +246,7 @@ void debug_int( const char *file, const char *function, const unsigned long line
246
log_date(date, LOG_DATE_LENGTH);
247
248
va_start( args, fmt );
249
- printf("%s: %s DEBUG (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function);
249
+ printf("%s: %s DEBUG : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function);
250
vprintf(fmt, args);
251
va_end( args );
252
putchar('\n');
@@ -282,8 +282,8 @@ void info_int( const char *file, const char *function, const unsigned long line,
282
log_lock();
283
284
va_start( args, fmt );
285
- if(debug_flags) fprintf(stderr, "%s: %s INFO : (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function);
286
- else fprintf(stderr, "%s: %s INFO : ", date, program_name);
285
+ if(debug_flags) fprintf(stderr, "%s: %s INFO : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function);
286
+ else fprintf(stderr, "%s: %s INFO : %s : ", date, program_name, netdata_thread_tag());
287
vfprintf( stderr, fmt, args );
288
va_end( args );
289
@@ -338,8 +338,8 @@ void error_int( const char *prefix, const char *file, const char *function, cons
338
log_lock();
339
340
va_start( args, fmt );
341
- if(debug_flags) fprintf(stderr, "%s: %s %s: (%04lu@%-10.10s:%-15.15s): ", date, program_name, prefix, line, file, function);
342
- else fprintf(stderr, "%s: %s %s: ", date, program_name, prefix);
341
+ if(debug_flags) fprintf(stderr, "%s: %s %-5.5s : %s: (%04lu@%-10.10s:%-15.15s): ", date, program_name, prefix, netdata_thread_tag(), line, file, function);
342
+ else fprintf(stderr, "%s: %s %-5.5s : %s: ", date, program_name, prefix, netdata_thread_tag());
343
vfprintf( stderr, fmt, args );
344
va_end( args );
345
@@ -369,8 +369,8 @@ void fatal_int( const char *file, const char *function, const unsigned long line
369
log_lock();
370
371
va_start( args, fmt );
372
- if(debug_flags) fprintf(stderr, "%s: %s FATAL: (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function);
373
- else fprintf(stderr, "%s: %s FATAL: ", date, program_name);
372
+ if(debug_flags) fprintf(stderr, "%s: %s FATAL : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function);
373
+ else fprintf(stderr, "%s: %s FATAL : %s :", date, program_name, netdata_thread_tag());
374
vfprintf( stderr, fmt, args );
375
va_end( args );
376
src/main.c
+33
-22
@@ -6,19 +6,30 @@ void netdata_cleanup_and_exit(int ret) {
6
netdata_exit = 1;
7
8
error_log_limit_unlimited();
9
- info("EXIT: netdata prepares to exit...");
9
+ info("EXIT: netdata prepares to exit with code %d...", ret);
10
11
- // stop everything
12
- info("EXIT: stopping master threads...");
13
- cancel_main_threads();
11
+ if(ret) {
12
+ // this is bad - exiting due to a fatal condition
13
15
- // cleanup the database (delete files not needed)
16
- info("EXIT: cleaning up the database...");
17
- rrdhost_cleanup_all();
14
+ // cleanup/save the database and exit
15
+ info("EXIT: cleaning up the database...");
16
+ rrdhost_cleanup_all();
17
+ }
18
+ else {
19
+ // exit cleanly
20
+
21
+ // stop everything
22
+ info("EXIT: stopping master threads...");
23
+ cancel_main_threads();
24
19
- // free the database
20
- info("EXIT: freeing database memory...");
21
- rrdhost_free_all();
25
+ // cleanup the database (delete files not needed)
26
+ info("EXIT: cleaning up the database...");
27
+ rrdhost_cleanup_all();
28
+
29
+ // free the database
30
+ info("EXIT: freeing database memory...");
31
+ rrdhost_free_all();
32
+ }
33
34
// unlink the pid
35
if(pidfile[0]) {
@@ -36,36 +47,36 @@ struct netdata_static_thread static_threads[] = {
47
#ifdef INTERNAL_PLUGIN_NFACCT
48
// nfacct requires root access
49
// so, we build it as an external plugin with setuid to root
39
- {"PLUGIN_NFACCT", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
50
+ {"PLUGIN[nfacct]", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
51
#endif
52
53
#ifdef NETDATA_INTERNAL_CHECKS
54
// debugging plugin
44
- {"PLUGIN_CHECK", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
55
+ {"PLUGIN[check]", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
56
#endif
57
58
#if defined(__FreeBSD__)
59
// FreeBSD internal plugins
49
- {"PLUGIN_FREEBSD", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
60
+ {"PLUGIN[freebsd]", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
61
#elif defined(__APPLE__)
62
// macOS internal plugins
52
- {"PLUGIN_MACOS", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
63
+ {"PLUGIN[macos]", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
64
#else
65
// linux internal plugins
55
- {"PLUGIN_PROC", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
56
- {"PLUGIN_DISKSPACE", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
57
- {"PLUGIN_CGROUP", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
58
- {"PLUGIN_TC", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
66
+ {"PLUGIN[proc]", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
67
+ {"PLUGIN[diskspace]", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
68
+ {"PLUGIN[cgroup]", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
69
+ {"PLUGIN[tc]", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
70
#endif /* __FreeBSD__, __APPLE__*/
71
72
// common plugins for all systems
62
- {"PLUGIN_IDLEJITTER", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
73
+ {"PLUGIN[idlejitter]", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
74
{"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
75
{"HEALTH", NULL, NULL, 1, NULL, NULL, health_main},
76
{"PLUGINSD", NULL, NULL, 1, NULL, NULL, pluginsd_main},
66
- {"WEB_SERVER", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
67
- {"WEB_SERVER_SINGLE_THREADED", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
68
- {"STREAMING", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
77
+ {"WEB_SERVER[multi]", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
78
+ {"WEB_SERVER[single]", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
79
+ {"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
80
{"STATSD", NULL, NULL, 1, NULL, NULL, statsd_main},
81
82
{NULL, NULL, NULL, 0, NULL, NULL, NULL}
src/plugins_d.c
+48
-48
@@ -131,7 +131,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
131
clearerr(fp);
132
133
if(unlikely(fileno(fp) == -1)) {
134
- error("PLUGINSD: %s: file is not a valid stream.", cd->fullfilename);
134
+ error("file descriptor given is not a valid stream");
135
goto cleanup;
136
}
137
@@ -140,7 +140,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
140
141
char *r = fgets(line, PLUGINSD_LINE_MAX, fp);
142
if(unlikely(!r)) {
143
- error("PLUGINSD: %s : read failed.", cd->fullfilename);
143
+ error("read failed");
144
break;
145
}
146
@@ -148,12 +148,9 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
148
149
line[PLUGINSD_LINE_MAX] = '\0';
150
151
- // debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
152
-
151
int w = pluginsd_split_words(line, words, PLUGINSD_MAX_WORDS);
152
char *s = words[0];
153
if(unlikely(!s || !*s || !w)) {
156
- // debug(D_PLUGINSD, "PLUGINSD: empty line");
154
continue;
155
}
156
@@ -164,7 +161,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
161
char *value = words[2];
162
163
if(unlikely(!dimension || !*dimension)) {
167
- error("PLUGINSD: '%s' is requesting a SET on chart '%s' of host '%s', without a dimension. Disabling it.", cd->fullfilename, st->id, host->hostname);
164
+ error("requested a SET on chart '%s' of host '%s', without a dimension. Disabling it.", st->id, host->hostname);
165
enabled = 0;
166
break;
167
}
@@ -172,17 +169,18 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
169
if(unlikely(!value || !*value)) value = NULL;
170
171
if(unlikely(!st)) {
175
- error("PLUGINSD: '%s' is requesting a SET on dimension %s with value %s on host '%s', without a BEGIN. Disabling it.", cd->fullfilename, dimension, value?value:"<nothing>", host->hostname);
172
+ error("requested a SET on dimension %s with value %s on host '%s', without a BEGIN. Disabling it.", dimension, value?value:"<nothing>", host->hostname);
173
enabled = 0;
174
break;
175
}
176
180
- if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) debug(D_PLUGINSD, "PLUGINSD: '%s' is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value?value:"<nothing>");
177
+ if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
178
+ debug(D_PLUGINSD, "is setting dimension %s/%s to %s", st->id, dimension, value?value:"<nothing>");
179
180
if(value) {
181
RRDDIM *rd = rrddim_find(st, dimension);
182
if(unlikely(!rd)) {
185
- error("PLUGINSD: '%s' is requesting a SET to dimension with id '%s' on stats '%s' (%s) on host '%s', which does not exist. Disabling it.", cd->fullfilename, dimension, st->name, st->id, st->rrdhost->hostname);
183
+ error("requested a SET to dimension with id '%s' on stats '%s' (%s) on host '%s', which does not exist. Disabling it.", dimension, st->name, st->id, st->rrdhost->hostname);
184
enabled = 0;
185
break;
186
}
@@ -195,14 +193,14 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
193
char *microseconds_txt = words[2];
194
195
if(unlikely(!id)) {
198
- error("PLUGINSD: '%s' is requesting a BEGIN without a chart id for host '%s'. Disabling it.", cd->fullfilename, host->hostname);
196
+ error("requested a BEGIN without a chart id for host '%s'. Disabling it.", host->hostname);
197
enabled = 0;
198
break;
199
}
200
201
st = rrdset_find(host, id);
202
if(unlikely(!st)) {
205
- error("PLUGINSD: '%s' is requesting a BEGIN on chart '%s', which does not exist on host '%s'. Disabling it.", cd->fullfilename, id, host->hostname);
203
+ error("requested a BEGIN on chart '%s', which does not exist on host '%s'. Disabling it.", id, host->hostname);
204
enabled = 0;
205
break;
206
}
@@ -222,12 +220,13 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
220
}
221
else if(likely(hash == END_HASH && !strcmp(s, PLUGINSD_KEYWORD_END))) {
222
if(unlikely(!st)) {
225
- error("PLUGINSD: '%s' is requesting an END, without a BEGIN on host '%s'. Disabling it.", cd->fullfilename, host->hostname);
223
+ error("requested an END, without a BEGIN on host '%s'. Disabling it.", host->hostname);
224
enabled = 0;
225
break;
226
}
227
230
- if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting an END on chart %s", cd->fullfilename, st->id);
228
+ if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
229
+ debug(D_PLUGINSD, "requested an END on chart %s", st->id);
230
231
rrdset_done(st);
232
st = NULL;
@@ -259,7 +258,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
258
259
// make sure we have the required variables
260
if(unlikely(!type || !*type || !id || !*id)) {
262
- error("PLUGINSD: '%s' is requesting a CHART, without a type.id, on host '%s'. Disabling it.", cd->fullfilename, host->hostname);
261
+ error("requested a CHART, without a type.id, on host '%s'. Disabling it.", host->hostname);
262
enabled = 0;
263
break;
264
}
@@ -295,7 +294,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
294
if(unlikely(!title)) title = "";
295
if(unlikely(!units)) units = "unknown";
296
298
- debug(D_PLUGINSD, "PLUGINSD: Creating chart type='%s', id='%s', name='%s', family='%s', context='%s', chart='%s', priority=%d, update_every=%d"
297
+ debug(D_PLUGINSD, "creating chart type='%s', id='%s', name='%s', family='%s', context='%s', chart='%s', priority=%d, update_every=%d"
298
, type, id
299
, name?name:""
300
, family?family:""
@@ -352,13 +351,13 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
351
char *options = words[6];
352
353
if(unlikely(!id || !*id)) {
355
- error("PLUGINSD: '%s' is requesting a DIMENSION, without an id, host '%s' and chart '%s'. Disabling it.", cd->fullfilename, host->hostname, st?st->id:"UNSET");
354
+ error("requested a DIMENSION, without an id, host '%s' and chart '%s'. Disabling it.", host->hostname, st?st->id:"UNSET");
355
enabled = 0;
356
break;
357
}
358
359
if(unlikely(!st)) {
361
- error("PLUGINSD: '%s' is requesting a DIMENSION, without a CHART, on host '%s'. Disabling it.", cd->fullfilename, host->hostname);
360
+ error("requested a DIMENSION, without a CHART, on host '%s'. Disabling it.", host->hostname);
361
enabled = 0;
362
break;
363
}
@@ -374,7 +373,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
373
if(unlikely(!algorithm || !*algorithm)) algorithm = "absolute";
374
375
if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
377
- debug(D_PLUGINSD, "PLUGINSD: Creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
376
+ debug(D_PLUGINSD, "creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
377
, st->id
378
, id
379
, name?name:""
@@ -412,7 +411,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
411
}
412
413
if(unlikely(!name || !*name)) {
415
- error("PLUGINSD: '%s' is requesting a VARIABLE on host '%s', without a variable name. Disabling it.", cd->fullfilename, host->hostname);
414
+ error("requested a VARIABLE on host '%s', without a variable name. Disabling it.", host->hostname);
415
enabled = 0;
416
break;
417
}
@@ -426,38 +425,38 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
425
426
if(unlikely(endptr && *endptr)) {
427
if(endptr == value)
429
- error("PLUGINSD: '%s': the value '%s' of VARIABLE '%s' on host '%s' cannot be parsed as a number", cd->fullfilename, value, name, host->hostname);
428
+ error("the value '%s' of VARIABLE '%s' on host '%s' cannot be parsed as a number", value, name, host->hostname);
429
else
431
- error("PLUGINSD: '%s': the value '%s' of VARIABLE '%s' on host '%s' has leftovers: '%s'", cd->fullfilename, value, name, host->hostname, endptr);
430
+ error("the value '%s' of VARIABLE '%s' on host '%s' has leftovers: '%s'", value, name, host->hostname, endptr);
431
}
432
433
if(global) {
434
RRDVAR *rv = rrdvar_custom_host_variable_create(host, name);
435
if (rv) rrdvar_custom_host_variable_set(host, rv, v);
437
- else error("PLUGINSD: '%s': cannot find/create HOST VARIABLE '%s' on host '%s'", cd->fullfilename, name, host->hostname);
436
+ else error("cannot find/create HOST VARIABLE '%s' on host '%s'", name, host->hostname);
437
}
438
else if(st) {
439
RRDSETVAR *rs = rrdsetvar_custom_chart_variable_create(st, name);
440
if (rs) rrdsetvar_custom_chart_variable_set(rs, v);
442
- else error("PLUGINSD: '%s': cannot find/create CHART VARIABLE '%s' on host '%s', chart '%s'", cd->fullfilename, name, host->hostname, st->id);
441
+ else error("cannot find/create CHART VARIABLE '%s' on host '%s', chart '%s'", name, host->hostname, st->id);
442
}
443
else
445
- error("PLUGINSD: '%s': cannot find/create CHART VARIABLE '%s' on host '%s' without a chart", cd->fullfilename, name, host->hostname);
444
+ error("cannot find/create CHART VARIABLE '%s' on host '%s' without a chart", name, host->hostname);
445
}
446
else
448
- error("PLUGINSD: '%s': cannot set %s VARIABLE '%s' on host '%s' to an empty value", cd->fullfilename, (global)?"HOST":"CHART", name, host->hostname);
447
+ error("cannot set %s VARIABLE '%s' on host '%s' to an empty value", (global)?"HOST":"CHART", name, host->hostname);
448
}
449
else if(likely(hash == FLUSH_HASH && !strcmp(s, PLUGINSD_KEYWORD_FLUSH))) {
451
- debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a FLUSH", cd->fullfilename);
450
+ debug(D_PLUGINSD, "requested a FLUSH");
451
st = NULL;
452
}
453
else if(unlikely(hash == DISABLE_HASH && !strcmp(s, PLUGINSD_KEYWORD_DISABLE))) {
455
- info("PLUGINSD: '%s' called DISABLE. Disabling it.", cd->fullfilename);
454
+ info("called DISABLE. Disabling it.");
455
enabled = 0;
456
break;
457
}
458
else {
460
- error("PLUGINSD: '%s' is sending command '%s' which is not known by netdata, for host '%s'. Disabling it.", cd->fullfilename, s, host->hostname);
459
+ error("sent command '%s' which is not known by netdata, for host '%s'. Disabling it.", s, host->hostname);
460
enabled = 0;
461
break;
462
}
@@ -482,15 +481,14 @@ static void pluginsd_worker_thread_cleanup(void *arg) {
481
if(cd->enabled && !cd->obsolete) {
482
cd->obsolete = 1;
483
485
- info("PLUGINSD: '%s' thread exiting", cd->fullfilename);
484
+ info("data collection thread exiting");
485
486
if (cd->pid) {
487
siginfo_t info;
489
- info("PLUGINSD: killing %s plugin child process pid %d", cd->id, cd->pid);
488
+ info("killing child process pid %d", cd->pid);
489
if (killpid(cd->pid, SIGTERM) != -1) {
491
- info("PLUGINSD: waiting for %s plugin child process pid %d to exit...", cd->id, cd->pid);
490
+ info("waiting for child process pid %d to exit...", cd->pid);
491
waitid(P_PID, (id_t) cd->pid, &info, WEXITED);
493
- info("PLUGINSD: finished %s plugin child process pid %d.", cd->id, cd->pid);
492
}
493
cd->pid = 0;
494
}
@@ -512,9 +510,9 @@ void *pluginsd_worker_thread(void *arg) {
510
break;
511
}
512
515
- info("%s on tid %d: connected to '%s' running on pid %d", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid);
513
+ info("connected to '%s' running on pid %d", cd->fullfilename, cd->pid);
514
count = pluginsd_process(localhost, cd, fp, 0);
517
- error("%s on tid %d: '%s' (pid %d) disconnected after %zu successful data collections (ENDs).", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, count);
515
+ error("'%s' (pid %d) disconnected after %zu successful data collections (ENDs).", cd->fullfilename, cd->pid, count);
516
killpid(cd->pid, SIGTERM);
517
518
// get the return code
@@ -525,18 +523,18 @@ void *pluginsd_worker_thread(void *arg) {
523
524
if(likely(!cd->successful_collections)) {
525
// nothing collected - disable it
528
- error("%s on tid %d: '%s' (pid %d) exited with error code %d. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code);
526
+ error("'%s' (pid %d) exited with error code %d. Disabling it.", cd->fullfilename, cd->pid, code);
527
cd->enabled = 0;
528
}
529
else {
530
// we have collected something
531
532
if(likely(cd->serial_failures <= 10)) {
535
- error("%s on tid %d: '%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). %s", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code, cd->successful_collections, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
533
+ error("'%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). %s", cd->fullfilename, cd->pid, code, cd->successful_collections, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
534
sleep((unsigned int) (cd->update_every * 10));
535
}
536
else {
539
- error("%s on tid %d: '%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). We tried %zu times to restart it, but it failed to generate data. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code, cd->successful_collections, cd->serial_failures);
537
+ error("'%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). We tried %zu times to restart it, but it failed to generate data. Disabling it.", cd->fullfilename, cd->pid, code, cd->successful_collections, cd->serial_failures);
538
cd->enabled = 0;
539
}
540
}
@@ -548,11 +546,11 @@ void *pluginsd_worker_thread(void *arg) {
546
// we have collected nothing so far
547
548
if(likely(cd->serial_failures <= 10)) {
551
- error("%s on tid %d: '%s' (pid %d) does not generate useful output but it reports success (exits with 0). %s.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is now disabled.");
549
+ error("'%s' (pid %d) does not generate useful output but it reports success (exits with 0). %s.", cd->fullfilename, cd->pid, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is now disabled.");
550
sleep((unsigned int) (cd->update_every * 10));
551
}
552
else {
555
- error("%s on tid %d: '%s' (pid %d) does not generate useful output, although it reports success (exits with 0), but we have tried %zu times to collect something. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, cd->serial_failures);
553
+ error("'%s' (pid %d) does not generate useful output, although it reports success (exits with 0), but we have tried %zu times to collect something. Disabling it.", cd->fullfilename, cd->pid, cd->serial_failures);
554
cd->enabled = 0;
555
}
556
}
@@ -573,17 +571,17 @@ static void pluginsd_main_cleanup(void *data) {
571
if(static_thread->enabled) {
572
static_thread->enabled = 0;
573
576
- info("%s: cleaning up...", netdata_thread_tag());
574
+ info("cleaning up...");
575
576
struct plugind *cd;
577
for (cd = pluginsd_root; cd; cd = cd->next) {
578
if (cd->enabled && !cd->obsolete) {
581
- info("PLUGINSD: Stopping plugin thread: %s", cd->id);
579
+ info("stopping plugin thread: %s", cd->id);
580
netdata_thread_cancel(cd->thread);
581
}
582
}
583
586
- info("%s: cleanup completed.", netdata_thread_tag());
584
+ info("cleanup completed.");
585
}
586
}
587
@@ -610,7 +608,7 @@ void *pluginsd_main(void *ptr) {
608
if(unlikely(!dir)) {
609
if(directory_errors[idx] != errno) {
610
directory_errors[idx] = errno;
613
- error("PLUGINSD: Cannot open plugins directory '%s'.", directory_name);
611
+ error("cannot open plugins directory '%s'", directory_name);
612
}
613
continue;
614
}
@@ -619,14 +617,14 @@ void *pluginsd_main(void *ptr) {
617
while(likely((file = readdir(dir)))) {
618
if(unlikely(netdata_exit)) break;
619
622
- debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name);
620
+ debug(D_PLUGINSD, "examining file '%s'", file->d_name);
621
622
if(unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue;
623
624
int len = (int) strlen(file->d_name);
625
if(unlikely(len <= (int)PLUGINSD_FILE_SUFFIX_LEN)) continue;
626
if(unlikely(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0)) {
629
- debug(D_PLUGINSD, "PLUGINSD: File '%s' does not end in '%s'.", file->d_name, PLUGINSD_FILE_SUFFIX);
627
+ debug(D_PLUGINSD, "file '%s' does not end in '%s'", file->d_name, PLUGINSD_FILE_SUFFIX);
628
continue;
629
}
630
@@ -635,7 +633,7 @@ void *pluginsd_main(void *ptr) {
633
int enabled = config_get_boolean(CONFIG_SECTION_PLUGINS, pluginname, automatic_run);
634
635
if(unlikely(!enabled)) {
638
- debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is not enabled", file->d_name);
636
+ debug(D_PLUGINSD, "plugin '%s' is not enabled", file->d_name);
637
continue;
638
}
639
@@ -645,7 +643,7 @@ void *pluginsd_main(void *ptr) {
643
if(unlikely(strcmp(cd->filename, file->d_name) == 0)) break;
644
645
if(likely(cd && !cd->obsolete)) {
648
- debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is already running", cd->filename);
646
+ debug(D_PLUGINSD, "plugin '%s' is already running", cd->filename);
647
continue;
648
}
649
@@ -674,8 +672,10 @@ void *pluginsd_main(void *ptr) {
672
cd->obsolete = 1;
673
674
if(cd->enabled) {
675
+ char tag[NETDATA_THREAD_TAG_MAX + 1];
676
+ snprintfz(tag, NETDATA_THREAD_TAG_MAX, "PLUGINSD[%s]", pluginname);
677
// spawn a new thread for it
678
- netdata_thread_create(&cd->thread, "PLUGINSD_COLLECTOR", NETDATA_THREAD_OPTION_DEFAULT, pluginsd_worker_thread, cd);
678
+ netdata_thread_create(&cd->thread, tag, NETDATA_THREAD_OPTION_DEFAULT, pluginsd_worker_thread, cd);
679
}
680
}
681
}
src/rrdpush.c
+8
-2
@@ -912,7 +912,10 @@ static void rrdpush_sender_thread_spawn(RRDHOST *host) {
912
rrdhost_wrlock(host);
913
914
if(!host->rrdpush_sender_spawn) {
915
- if(netdata_thread_create(&host->rrdpush_sender_thread, "STREAM_SENDER", NETDATA_THREAD_OPTION_JOINABLE, rrdpush_sender_thread, (void *) host))
915
+ char tag[NETDATA_THREAD_TAG_MAX + 1];
916
+ snprintfz(tag, NETDATA_THREAD_TAG_MAX, "STREAM_SENDER[%s]", host->hostname);
917
+
918
+ if(netdata_thread_create(&host->rrdpush_sender_thread, tag, NETDATA_THREAD_OPTION_JOINABLE, rrdpush_sender_thread, (void *) host))
919
error("STREAM %s [send]: failed to create new thread for client.", host->hostname);
920
else
921
host->rrdpush_sender_spawn = 1;
@@ -1050,7 +1053,10 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
1053
1054
debug(D_SYSTEM, "STREAM [receive from [%s]:%s]: starting receiving thread.", w->client_ip, w->client_port);
1055
1053
- if(netdata_thread_create(&thread, "STREAM_RECEIVER", NETDATA_THREAD_OPTION_DEFAULT, rrdpush_receiver_thread, (void *)rpt))
1056
+ char tag[FILENAME_MAX + 1];
1057
+ snprintfz(tag, FILENAME_MAX, "STREAM_RECEIVER[[%s]:%s]", w->client_ip, w->client_port);
1058
+
1059
+ if(netdata_thread_create(&thread, tag, NETDATA_THREAD_OPTION_DEFAULT, rrdpush_receiver_thread, (void *)rpt))
1060
error("STREAM [receive from [%s]:%s]: failed to create new thread for client.", w->client_ip, w->client_port);
1061
1062
// prevent the caller from closing the streaming socket
src/statsd.c
+5
-2
@@ -2085,8 +2085,11 @@ void *statsd_main(void *ptr) {
2085
2086
statsd.collection_threads = callocz((size_t)statsd.threads, sizeof(netdata_thread_t));
2087
int i;
2088
- for(i = 0; i < statsd.threads ;i++)
2089
- netdata_thread_create(&statsd.collection_threads[i], "STATSD_COLLECTOR", NETDATA_THREAD_OPTION_DEFAULT, statsd_collector_thread, &i);
2088
+ for(i = 0; i < statsd.threads ;i++) {
2089
+ char tag[NETDATA_THREAD_TAG_MAX + 1];
2090
+ snprintfz(tag, NETDATA_THREAD_TAG_MAX, "STATSD_COLLECTOR[%d]", i + 1);
2091
+ netdata_thread_create(&statsd.collection_threads[i], tag, NETDATA_THREAD_OPTION_DEFAULT, statsd_collector_thread, &i);
2092
+ }
2093
2094
// ----------------------------------------------------------------------------------------------------------------
2095
// statsd monitoring charts
src/threads.c
+1
-1
@@ -17,7 +17,7 @@ typedef struct {
17
static __thread NETDATA_THREAD *netdata_thread = NULL;
18
19
const char *netdata_thread_tag(void) {
20
- return ((netdata_thread && netdata_thread->tag && *netdata_thread->tag)?netdata_thread->tag:"unknown");
20
+ return ((netdata_thread && netdata_thread->tag && *netdata_thread->tag)?netdata_thread->tag:"MAIN");
21
}
22
23
// ----------------------------------------------------------------------------
src/threads.h
+1
@@ -16,6 +16,7 @@ typedef enum {
16
17
typedef pthread_t netdata_thread_t;
18
19
+#define NETDATA_THREAD_TAG_MAX 50
20
extern const char *netdata_thread_tag(void);
21
22
extern size_t netdata_threads_init(void);
src/web_server.c
+4
-1
@@ -193,7 +193,10 @@ void *socket_listen_main_multi_threaded(void *ptr) {
193
else
194
web_client_set_tcp(w);
195
196
- if(netdata_thread_create(&w->thread, "WEB_CLIENT", NETDATA_THREAD_OPTION_DONT_LOG, web_client_main, w) != 0)
196
+ char tag[NETDATA_THREAD_TAG_MAX + 1];
197
+ snprintfz(tag, NETDATA_THREAD_TAG_MAX, "WEB_CLIENT[%llu,[%s]:%s]", w->id, w->client_ip, w->client_port);
198
+
199
+ if(netdata_thread_create(&w->thread, tag, NETDATA_THREAD_OPTION_DONT_LOG, web_client_main, w) != 0)
200
WEB_CLIENT_IS_OBSOLETE(w);
201
}
202
}