@cryptotaxi247 / netdata-1 / commits / 16ab300ab

added more debug info in streaming

Costa Tsaousis (ktsaou) committed May 7, 2017 at 12:56 UTC 16ab300ab752ad0d18fdc500c2abb5de1e39ab77
1 file changed +18 -11
src/rrdpush.c
+18 -11
@@ -360,6 +360,8 @@ void *rrdpush_sender_thread(void *ptr) {
360
361 // allow appending data into rrdpush_buffer
362 host->rrdpush_connected = 1;
363 +
364 + debug(D_STREAM, "Connected...");
365 }
366
367 ifd->fd = host->rrdpush_pipe[PIPE_READ];
@@ -379,13 +381,13 @@ void *rrdpush_sender_thread(void *ptr) {
381 fdmax = 1;
382 }
383
382 - debug(D_STREAM, "STREAM: Waiting for poll() events...");
384 + debug(D_STREAM, "STREAM: Waiting for poll() events (current buffer length %zu bytes)...", buffer_strlen(host->rrdpush_buffer));
385 if(netdata_exit) break;
386 int retval = poll(fds, fdmax, 1000);
387 if(netdata_exit) break;
388
389 if(unlikely(retval == -1)) {
388 - debug(D_STREAM, "STREAM: poll() failed...");
390 + debug(D_STREAM, "STREAM: poll() failed (current buffer length %zu bytes)...", buffer_strlen(host->rrdpush_buffer));
391
392 if(errno == EAGAIN || errno == EINTR) {
393 debug(D_STREAM, "STREAM: poll() failed with EAGAIN or EINTR...");
@@ -399,7 +401,7 @@ void *rrdpush_sender_thread(void *ptr) {
401 }
402 else if(likely(retval)) {
403 if (ifd->revents & POLLIN) {
402 - debug(D_STREAM, "STREAM: Data added to send buffer...");
404 + debug(D_STREAM, "STREAM: Data added to send buffer (current buffer length %zu bytes)...", buffer_strlen(host->rrdpush_buffer));
405
406 char buffer[1000 + 1];
407 if (read(host->rrdpush_pipe[PIPE_READ], buffer, 1000) == -1)
@@ -407,7 +409,7 @@ void *rrdpush_sender_thread(void *ptr) {
409 }
410
411 if (ofd->revents & POLLOUT && begin < buffer_strlen(host->rrdpush_buffer)) {
410 - debug(D_STREAM, "STREAM: Sending socket is ready for output...");
412 + debug(D_STREAM, "STREAM: Sending data (current buffer length %zu bytes)...", buffer_strlen(host->rrdpush_buffer));
413
414 // BEGIN RRDPUSH LOCKED SESSION
415
@@ -422,20 +424,20 @@ void *rrdpush_sender_thread(void *ptr) {
424 debug(D_STREAM, "STREAM: Getting exclusive lock on host...");
425 rrdpush_lock(host);
426
425 - debug(D_STREAM, "STREAM: Sending data from %zu to %zu...", begin, buffer_strlen(host->rrdpush_buffer));
427 + debug(D_STREAM, "STREAM: Sending data, starting from %zu, size %zu...", begin, buffer_strlen(host->rrdpush_buffer));
428 ssize_t ret = send(host->rrdpush_socket, &host->rrdpush_buffer->buffer[begin], buffer_strlen(host->rrdpush_buffer) - begin, MSG_DONTWAIT);
429 if (unlikely(ret == -1)) {
428 - debug(D_STREAM, "STREAM: Send failed...");
429 -
430 if (errno != EAGAIN && errno != EINTR && errno != EWOULDBLOCK) {
431 + debug(D_STREAM, "STREAM: Send failed - closing socket...");
432 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);
433 close(host->rrdpush_socket);
434 host->rrdpush_socket = -1;
435 }
436 + else {
437 + debug(D_STREAM, "STREAM: Send failed - will retry...");
438 + }
439 }
440 else if(likely(ret > 0)) {
437 - debug(D_STREAM, "STREAM: Sent %zd bytes...", ret);
438 -
441 sent_connection += ret;
442 sent_bytes += ret;
443 begin += ret;
@@ -443,13 +445,18 @@ void *rrdpush_sender_thread(void *ptr) {
445 if (begin == buffer_strlen(host->rrdpush_buffer)) {
446 // we send it all
447
448 + debug(D_STREAM, "STREAM: Sent %zd bytes (the whole buffer)...", ret);
449 buffer_flush(host->rrdpush_buffer);
450 begin = 0;
451 }
452 + else {
453 + debug(D_STREAM, "STREAM: Sent %zd bytes (part of the data buffer)...", ret);
454 + }
455
456 last_sent_t = now_monotonic_sec();
457 }
458 else {
459 + debug(D_STREAM, "STREAM: send() returned %zd - closing the socket...", ret);
460 error("STREAM %s [send to %s]: failed to send metrics (send() returned %zd) - closing connection - we have sent %zu bytes on this connection.", host->hostname, connected_to, ret, sent_connection);
461 close(host->rrdpush_socket);
462 host->rrdpush_socket = -1;
@@ -469,8 +476,8 @@ void *rrdpush_sender_thread(void *ptr) {
476 }
477
478 // protection from overflow
472 - debug(D_STREAM, "STREAM: Checking for buffer overflow...");
473 - if(host->rrdpush_buffer->len > max_size) {
479 + if(buffer_strlen(host->rrdpush_buffer) > max_size) {
480 + debug(D_STREAM, "STREAM: Buffer is too big (%zu bytes), bigger than the max (%zu) - flushing it...", buffer_strlen(host->rrdpush_buffer), max_size);
481 errno = 0;
482 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);
483 if(host->rrdpush_socket != -1) {