Skip to content

Commit

Permalink
bin: upon CONT unix signal, dump internal status to stdout
Browse files Browse the repository at this point in the history
Now Fluent Bit receives a CONT unix signal, it will dump internals
about memory usage and chunks to stdout, e.g:

  kill -CONT `pidof fluent-bit`

output:

[engine] caught signal (SIGCONT)
[2020/03/18 18:21:49] Fluent Bit Dump

===== Input =====
syslog_debug (syslog)
│
├─ status
│  └─ overlimit     : no
│     ├─ mem size   : 0b (0 bytes)
│     └─ mem limit  : 61.0M (64000000 bytes)
│
├─ tasks
│  ├─ total tasks   : 0
│  ├─ new           : 0
│  ├─ running       : 0
│  └─ size          : 0b (0 bytes)
│
└─ chunks
   └─ total chunks  : 0
      ├─ up chunks  : 0
      ├─ down chunks: 0
      └─ busy chunks: 0
         ├─ size    : 0b (0 bytes)
         └─ size err: 0

storage_backlog.1 (storage_backlog)
│
├─ status
│  └─ overlimit     : no
│     ├─ mem size   : 0b (0 bytes)
│     └─ mem limit  : 0b (0 bytes)
│
├─ tasks
│  ├─ total tasks   : 17
│  ├─ new           : 16
│  ├─ running       : 1
│  └─ size          : 32.2M (33714420 bytes)
│
└─ chunks
   └─ total chunks  : 17
      ├─ up chunks  : 17
      ├─ down chunks: 0
      └─ busy chunks: 17
         ├─ size    : 32.2M (33714420 bytes)
         └─ size err: 0

===== Storage Layer =====
total chunks     : 26
├─ mem chunks    : 0
└─ fs chunks     : 26
   ├─ up         : 17

Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
  • Loading branch information
edsiper committed Mar 19, 2020
1 parent 3e5258d commit f07fdab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ endif()
if(FLB_BACKTRACE)
FLB_DEFINITION(FLB_HAVE_LIBBACKTRACE)
ExternalProject_Add(backtrace
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-5a99ff7f/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-5a99ff7f/configure ${AUTOCONF_HOST_OPT} --prefix=<INSTALL_DIR> --enable-shared=no --enable-static=yes
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-ca0de05/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-ca0de05/configure ${AUTOCONF_HOST_OPT} --prefix=<INSTALL_DIR> --enable-shared=no --enable-static=yes
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND $(MAKE) DESTDIR= install
)
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ endif()
# Binary / Executable
if(FLB_BINARY)
find_package (Threads)
add_executable(fluent-bit-bin fluent-bit.c)
add_executable(fluent-bit-bin fluent-bit.c flb_dump.c)
add_sanitizers(fluent-bit-bin)


if(FLB_STATIC_CONF)
add_dependencies(fluent-bit-bin flb-static-conf)
endif()
Expand All @@ -321,6 +322,7 @@ if(FLB_BINARY)
endif()

if(FLB_BACKTRACE)
add_definitions(-DFLB_DUMP_STACKTRACE=1)
target_link_libraries(fluent-bit-bin libbacktrace)
endif()

Expand Down
61 changes: 7 additions & 54 deletions src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <monkey/mk_core.h>
#include <fluent-bit/flb_compat.h>
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_dump.h>
#include <fluent-bit/flb_stacktrace.h>
#include <fluent-bit/flb_env.h>
#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_utils.h>
Expand All @@ -45,61 +47,7 @@
#include <fluent-bit/flb_plugin.h>
#include <fluent-bit/flb_parser.h>

/* Libbacktrace support */
#ifdef FLB_HAVE_LIBBACKTRACE
#include <backtrace.h>
#include <backtrace-supported.h>

struct flb_stacktrace {
struct backtrace_state *state;
int error;
int line;
};

struct flb_stacktrace flb_st;

static void flb_stacktrace_error_callback(void *data,
const char *msg, int errnum)
{
struct flb_stacktrace *ctx = data;
fprintf(stderr, "ERROR: %s (%d)", msg, errnum);
ctx->error = 1;
}

static int flb_stacktrace_print_callback(void *data, uintptr_t pc,
const char *filename, int lineno,
const char *function)
{
struct flb_stacktrace *p = data;

fprintf(stdout, "#%-2i 0x%-17lx in %s() at %s:%d\n",
p->line,
(unsigned long) pc,
function == NULL ? "???" : function,
filename == NULL ? "???" : filename + sizeof(FLB_SOURCE_DIR),
lineno);
p->line++;
return 0;
}

static inline void flb_stacktrace_init(char *prog)
{
memset(&flb_st, '\0', sizeof(struct flb_stacktrace));
flb_st.state = backtrace_create_state(prog,
BACKTRACE_SUPPORTS_THREADS,
flb_stacktrace_error_callback, NULL);
}

void flb_stacktrace_print()
{
struct flb_stacktrace *ctx;

ctx = &flb_st;
backtrace_full(ctx->state, 3, flb_stacktrace_print_callback,
flb_stacktrace_error_callback, ctx);
}

#endif

#ifdef FLB_HAVE_MTRACE
#include <mcheck.h>
Expand Down Expand Up @@ -421,6 +369,7 @@ static void flb_signal_handler(int signal)
#endif
flb_print_signal(SIGTERM);
flb_print_signal(SIGSEGV);
flb_print_signal(SIGCONT);
};

/* Signal handlers */
Expand All @@ -444,6 +393,9 @@ static void flb_signal_handler(int signal)
flb_stacktrace_print();
#endif
abort();
case SIGCONT:
flb_dump(config);
break;
default:
break;
}
Expand All @@ -458,6 +410,7 @@ static void flb_signal_init()
#endif
signal(SIGTERM, &flb_signal_handler);
signal(SIGSEGV, &flb_signal_handler);
signal(SIGCONT, &flb_signal_handler);
}

static int input_set_property(struct flb_input_instance *in, char *kv)
Expand Down

0 comments on commit f07fdab

Please sign in to comment.