log the hostname on all rrdpush logs
Costa Tsaousis (ktsaou) committed
Feb 25, 2017 at 01:10 UTC
932db299e49459b28da0c90565efa854a3d2eaa9
1 file changed
+46
-43
src/rrdpush.c
+46
-43
@@ -129,7 +129,7 @@ void rrdset_done_push(RRDSET *st) {
129
130
if(unlikely(!host->rrdpush_buffer || !host->rrdpush_connected)) {
131
if(unlikely(!host->rrdpush_error_shown))
132
- error("STREAM [send]: not ready - discarding collected metrics.");
132
+ error("STREAM %s [send]: not ready - discarding collected metrics.", host->hostname);
133
134
host->rrdpush_error_shown = 1;
135
@@ -137,7 +137,7 @@ void rrdset_done_push(RRDSET *st) {
137
return;
138
}
139
else if(unlikely(host->rrdpush_error_shown)) {
140
- error("STREAM [send]: ready - sending metrics...");
140
+ info("STREAM %s [send]: ready - sending metrics...", host->hostname);
141
host->rrdpush_error_shown = 0;
142
}
143
@@ -148,7 +148,7 @@ void rrdset_done_push(RRDSET *st) {
148
149
// signal the sender there are more data
150
if(write(host->rrdpush_pipe[PIPE_WRITE], " ", 1) == -1)
151
- error("STREAM [send]: cannot write to internal pipe");
151
+ error("STREAM %s [send]: cannot write to internal pipe", host->hostname);
152
153
rrdpush_unlock(host);
154
}
@@ -183,7 +183,7 @@ static void rrdpush_sender_thread_reset_all_charts(RRDHOST *host) {
183
static inline void rrdpush_sender_thread_data_flush(RRDHOST *host) {
184
rrdpush_lock(host);
185
if(buffer_strlen(host->rrdpush_buffer))
186
- error("STREAM [send]: discarding %zu bytes of metrics already in the buffer.", buffer_strlen(host->rrdpush_buffer));
186
+ error("STREAM %s [send]: discarding %zu bytes of metrics already in the buffer.", host->hostname, buffer_strlen(host->rrdpush_buffer));
187
188
buffer_flush(host->rrdpush_buffer);
189
rrdpush_sender_thread_reset_all_charts(host);
@@ -192,14 +192,14 @@ static inline void rrdpush_sender_thread_data_flush(RRDHOST *host) {
192
193
static inline void rrdpush_sender_thread_lock(RRDHOST *host) {
194
if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0)
195
- error("STREAM [send]: cannot set pthread cancel state to DISABLE.");
195
+ error("STREAM %s [send]: cannot set pthread cancel state to DISABLE.", host->hostname);
196
197
rrdpush_lock(host);
198
}
199
200
static inline void rrdpush_sender_thread_unlock(RRDHOST *host) {
201
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
202
- error("STREAM [send]: cannot set pthread cancel state to DISABLE.");
202
+ error("STREAM %s [send]: cannot set pthread cancel state to DISABLE.", host->hostname);
203
204
rrdpush_unlock(host);
205
}
@@ -229,13 +229,13 @@ void rrdpush_sender_thread_cleanup(RRDHOST *host) {
229
void *rrdpush_sender_thread(void *ptr) {
230
RRDHOST *host = (RRDHOST *)ptr;
231
232
- info("STREAM [send]: thread created (task id %d)", gettid());
232
+ info("STREAM %s [send]: thread created (task id %d)", host->hostname, gettid());
233
234
if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
235
- error("STREAM [send]: cannot set pthread cancel type to DEFERRED.");
235
+ error("STREAM %s [send]: cannot set pthread cancel type to DEFERRED.", host->hostname);
236
237
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
238
- error("STREAM [send]: cannot set pthread cancel state to ENABLE.");
238
+ error("STREAM %s [send]: cannot set pthread cancel state to ENABLE.", host->hostname);
239
240
int timeout = (int)config_get_number(CONFIG_SECTION_STREAM, "timeout seconds", 60);
241
int default_port = (int)config_get_number(CONFIG_SECTION_STREAM, "default port", 19999);
@@ -250,7 +250,7 @@ void *rrdpush_sender_thread(void *ptr) {
250
// initialize rrdpush globals
251
host->rrdpush_buffer = buffer_create(1);
252
host->rrdpush_connected = 0;
253
- if(pipe(host->rrdpush_pipe) == -1) fatal("STREAM [send]: cannot create required pipe.");
253
+ if(pipe(host->rrdpush_pipe) == -1) fatal("STREAM %s [send]: cannot create required pipe.", host->hostname);
254
255
// initialize local variables
256
size_t begin = 0;
@@ -276,16 +276,16 @@ void *rrdpush_sender_thread(void *ptr) {
276
// they will be lost, so there is no point to do it
277
host->rrdpush_connected = 0;
278
279
- info("STREAM [send to %s]: connecting...", rrdpush_destination);
279
+ info("STREAM %s [send to %s]: connecting...", host->hostname, rrdpush_destination);
280
host->rrdpush_socket = connect_to_one_of(rrdpush_destination, default_port, &tv, &reconnects_counter, connected_to, CONNECTED_TO_SIZE);
281
282
if(unlikely(host->rrdpush_socket == -1)) {
283
- error("STREAM [send to %s]: failed to connect", rrdpush_destination);
283
+ error("STREAM %s [send to %s]: failed to connect", host->hostname, rrdpush_destination);
284
sleep(reconnect_delay);
285
continue;
286
}
287
288
- info("STREAM [send to %s]: initializing communication...", connected_to);
288
+ info("STREAM %s [send to %s]: initializing communication...", host->hostname, connected_to);
289
290
char http[1000 + 1];
291
snprintfz(http, 1000,
@@ -303,17 +303,17 @@ void *rrdpush_sender_thread(void *ptr) {
303
if(send_timeout(host->rrdpush_socket, http, strlen(http), 0, timeout) == -1) {
304
close(host->rrdpush_socket);
305
host->rrdpush_socket = -1;
306
- error("STREAM [send to %s]: failed to send http header to netdata", connected_to);
306
+ error("STREAM %s [send to %s]: failed to send http header to netdata", host->hostname, connected_to);
307
sleep(reconnect_delay);
308
continue;
309
}
310
311
- info("STREAM [send to %s]: waiting response from remote netdata...", connected_to);
311
+ info("STREAM %s [send to %s]: waiting response from remote netdata...", host->hostname, connected_to);
312
313
if(recv_timeout(host->rrdpush_socket, http, 1000, 0, timeout) == -1) {
314
close(host->rrdpush_socket);
315
host->rrdpush_socket = -1;
316
- error("STREAM [send to %s]: failed to initialize communication", connected_to);
316
+ error("STREAM %s [send to %s]: failed to initialize communication", host->hostname, connected_to);
317
sleep(reconnect_delay);
318
continue;
319
}
@@ -321,15 +321,15 @@ void *rrdpush_sender_thread(void *ptr) {
321
if(strncmp(http, "STREAM", 6)) {
322
close(host->rrdpush_socket);
323
host->rrdpush_socket = -1;
324
- error("STREAM [send to %s]: server is not replying properly.", connected_to);
324
+ error("STREAM %s [send to %s]: server is not replying properly.", host->hostname, connected_to);
325
sleep(reconnect_delay);
326
continue;
327
}
328
329
- info("STREAM [send to %s]: established communication - sending metrics...", connected_to);
329
+ info("STREAM %s [send to %s]: established communication - sending metrics...", host->hostname, connected_to);
330
331
if(fcntl(host->rrdpush_socket, F_SETFL, O_NONBLOCK) < 0)
332
- error("STREAM [send to %s]: cannot set non-blocking mode for socket.", connected_to);
332
+ error("STREAM %s [send to %s]: cannot set non-blocking mode for socket.", host->hostname, connected_to);
333
334
rrdpush_sender_thread_data_flush(host);
335
sent_connection = 0;
@@ -361,7 +361,7 @@ void *rrdpush_sender_thread(void *ptr) {
361
if(errno == EAGAIN || errno == EINTR)
362
continue;
363
364
- error("STREAM [send to %s]: failed to poll().", connected_to);
364
+ error("STREAM %s [send to %s]: failed to poll().", host->hostname, connected_to);
365
close(host->rrdpush_socket);
366
host->rrdpush_socket = -1;
367
break;
@@ -374,7 +374,7 @@ void *rrdpush_sender_thread(void *ptr) {
374
if(ifd->revents & POLLIN) {
375
char buffer[1000 + 1];
376
if(read(host->rrdpush_pipe[PIPE_READ], buffer, 1000) == -1)
377
- error("STREAM [send to %s]: cannot read from internal pipe.", connected_to);
377
+ error("STREAM %s [send to %s]: cannot read from internal pipe.", host->hostname, connected_to);
378
}
379
380
if(ofd->revents & POLLOUT && begin < buffer_strlen(host->rrdpush_buffer)) {
@@ -382,7 +382,7 @@ void *rrdpush_sender_thread(void *ptr) {
382
ssize_t ret = send(host->rrdpush_socket, &host->rrdpush_buffer->buffer[begin], buffer_strlen(host->rrdpush_buffer) - begin, MSG_DONTWAIT);
383
if(ret == -1) {
384
if(errno != EAGAIN && errno != EINTR) {
385
- error("STREAM [send to %s]: failed to send metrics - closing connection - we have sent %zu bytes on this connection.", connected_to, sent_connection);
385
+ error("STREAM %s [send to %s]: failed to send metrics - closing connection - we have sent %zu bytes on this connection.", host->hostname, connected_to, sent_connection);
386
close(host->rrdpush_socket);
387
host->rrdpush_socket = -1;
388
}
@@ -402,7 +402,7 @@ void *rrdpush_sender_thread(void *ptr) {
402
// protection from overflow
403
if(host->rrdpush_buffer->len > max_size) {
404
errno = 0;
405
- error("STREAM [send to %s]: too many data pending - buffer is %zu bytes long, %zu unsent - we have sent %zu bytes in total, %zu on this connection. Closing connection to flush the data.", connected_to, host->rrdpush_buffer->len, host->rrdpush_buffer->len - begin, sent_bytes, sent_connection);
405
+ error("STREAM %s [send to %s]: too many data pending - buffer is %zu bytes long, %zu unsent - we have sent %zu bytes in total, %zu on this connection. Closing connection to flush the data.", host->hostname, connected_to, host->rrdpush_buffer->len, host->rrdpush_buffer->len - begin, sent_bytes, sent_connection);
406
if(host->rrdpush_socket != -1) {
407
close(host->rrdpush_socket);
408
host->rrdpush_socket = -1;
@@ -411,7 +411,7 @@ void *rrdpush_sender_thread(void *ptr) {
411
}
412
413
cleanup:
414
- debug(D_WEB_CLIENT, "STREAM [send]: sending thread exits.");
414
+ debug(D_WEB_CLIENT, "STREAM %s [send]: sending thread exits.", host->hostname);
415
416
rrdpush_sender_thread_cleanup(host);
417
@@ -451,13 +451,16 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
451
else
452
host = rrdhost_find_or_create(hostname, machine_guid, os, update_every, history, mode, health_enabled?1:0);
453
454
- info("STREAM [receive from [%s]:%s]: metrics for host '%s' with machine_guid '%s': update every = %d, history = %d, memory mode = %s, health %s",
455
- client_ip, client_port,
456
- hostname, machine_guid,
457
- update_every,
458
- history,
459
- rrd_memory_mode_name(mode),
460
- (health_enabled == CONFIG_BOOLEAN_NO)?"disabled":((health_enabled == CONFIG_BOOLEAN_YES)?"enabled":"auto")
454
+ info("STREAM %s [receive from [%s]:%s]: metrics for host '%s' with machine_guid '%s': update every = %d, history = %d, memory mode = %s, health %s"
455
+ , host->hostname
456
+ , client_ip
457
+ , client_port
458
+ , hostname
459
+ , machine_guid
460
+ , update_every
461
+ , history
462
+ , rrd_memory_mode_name(mode)
463
+ , (health_enabled == CONFIG_BOOLEAN_NO)?"disabled":((health_enabled == CONFIG_BOOLEAN_YES)?"enabled":"auto")
464
);
465
466
struct plugind cd = {
@@ -477,20 +480,20 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
480
snprintfz(cd.fullfilename, FILENAME_MAX, "%s:%s", client_ip, client_port);
481
snprintfz(cd.cmd, PLUGINSD_CMD_MAX, "%s:%s", client_ip, client_port);
482
480
- info("STREAM [receive from [%s]:%s]: initializing communication...", client_ip, client_port);
483
+ info("STREAM %s [receive from [%s]:%s]: initializing communication...", host->hostname, client_ip, client_port);
484
if(send_timeout(fd, "STREAM", 6, 0, 60) != 6) {
482
- error("STREAM [receive from [%s]:%s]: cannot send STREAM command.", client_ip, client_port);
485
+ error("STREAM %s [receive from [%s]:%s]: cannot send STREAM command.", host->hostname, client_ip, client_port);
486
return 0;
487
}
488
489
// remove the non-blocking flag from the socket
490
if(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK) == -1)
488
- error("STREAM [receive from [%s]:%s]: cannot remove the non-blocking flag from socket %d", client_ip, client_port, fd);
491
+ error("STREAM %s [receive from [%s]:%s]: cannot remove the non-blocking flag from socket %d", host->hostname, client_ip, client_port, fd);
492
493
// convert the socket to a FILE *
494
FILE *fp = fdopen(fd, "r");
495
if(!fp) {
493
- error("STREAM [receive from [%s]:%s]: failed to get a FILE for FD %d.", client_ip, client_port, fd);
496
+ error("STREAM %s [receive from [%s]:%s]: failed to get a FILE for FD %d.", host->hostname, client_ip, client_port, fd);
497
return 0;
498
}
499
@@ -501,9 +504,9 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
504
rrdhost_unlock(host);
505
506
// call the plugins.d processor to receive the metrics
504
- info("STREAM [receive from [%s]:%s]: receiving metrics... (host '%s', machine GUID '%s').", client_ip, client_port, host->hostname, host->machine_guid);
507
+ info("STREAM %s [receive from [%s]:%s]: receiving metrics... (host '%s', machine GUID '%s').", host->hostname, client_ip, client_port, host->hostname, host->machine_guid);
508
size_t count = pluginsd_process(host, &cd, fp, 1);
506
- error("STREAM [receive from [%s]:%s]: disconnected (host '%s', machine GUID '%s', completed updates %zu).", client_ip, client_port, host->hostname, host->machine_guid, count);
509
+ error("STREAM %s [receive from [%s]:%s]: disconnected (host '%s', machine GUID '%s', completed updates %zu).", host->hostname, client_ip, client_port, host->hostname, host->machine_guid, count);
510
511
rrdhost_wrlock(host);
512
host->use_counter--;
@@ -532,15 +535,15 @@ void *rrdpush_receiver_thread(void *ptr) {
535
struct rrdpush_thread *rpt = (struct rrdpush_thread *)ptr;
536
537
if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
535
- error("STREAM [receive]: cannot set pthread cancel type to DEFERRED.");
538
+ error("STREAM %s [receive]: cannot set pthread cancel type to DEFERRED.", rpt->hostname);
539
540
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
538
- error("STREAM [receive]: cannot set pthread cancel state to ENABLE.");
541
+ error("STREAM %s [receive]: cannot set pthread cancel state to ENABLE.", rpt->hostname);
542
543
541
- info("STREAM [%s]:%s: receive thread created (task id %d)", rpt->client_ip, rpt->client_port, gettid());
544
+ info("STREAM %s [%s]:%s: receive thread created (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid());
545
rrdpush_receive(rpt->fd, rpt->key, rpt->hostname, rpt->machine_guid, rpt->os, rpt->update_every, rpt->client_ip, rpt->client_port);
543
- info("STREAM [receive from [%s]:%s]: receive thread ended (task id %d)", rpt->client_ip, rpt->client_port, gettid());
546
+ info("STREAM %s [receive from [%s]:%s]: receive thread ended (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid());
547
548
close(rpt->fd);
549
freez(rpt->key);
@@ -561,10 +564,10 @@ static inline int rrdpush_receive_validate_api_key(const char *key) {
564
565
void rrdpush_sender_thread_spawn(RRDHOST *host) {
566
if(pthread_create(&host->rrdpush_thread, NULL, rrdpush_sender_thread, (void *)host))
564
- error("STREAM [send for host %s]: failed to create new thread for client.", host->hostname);
567
+ error("STREAM %s [send]: failed to create new thread for client.", host->hostname);
568
569
else if(pthread_detach(host->rrdpush_thread))
567
- error("STREAM [send for host %s]: cannot request detach newly created thread.", host->hostname);
570
+ error("STREAM %s [send]: cannot request detach newly created thread.", host->hostname);
571
572
host->rrdpush_spawn = 1;
573
}