relayd: register threads to health monitoring
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 16 Sep 2013 14:30:34 +0000 (09:30 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 9 Oct 2013 13:16:58 +0000 (09:16 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/bin/lttng-relayd/Makefile.am
src/bin/lttng-relayd/health-relayd.h [new file with mode: 0644]
src/bin/lttng-relayd/main.c

index 4f23dbc437456733c438564955c339a1ab3a7d94..fc8e6d055be2286c4df7149747528a0e5742df69 100644 (file)
@@ -11,7 +11,8 @@ lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c cmd.h \
                        cmd-generic.c cmd-generic.h \
                        cmd-2-1.c cmd-2-1.h \
                        cmd-2-2.c cmd-2-2.h \
-                       cmd-2-4.c cmd-2-4.h
+                       cmd-2-4.c cmd-2-4.h \
+                       health-relayd.h
 
 # link on liblttngctl for check if relayd is already alive.
 lttng_relayd_LDADD = -lrt -lurcu-common -lurcu \
@@ -20,4 +21,5 @@ lttng_relayd_LDADD = -lrt -lurcu-common -lurcu \
                $(top_builddir)/src/common/hashtable/libhashtable.la \
                $(top_builddir)/src/common/libcommon.la \
                $(top_builddir)/src/common/compat/libcompat.la \
-               $(top_builddir)/src/common/index/libindex.la
+               $(top_builddir)/src/common/index/libindex.la \
+               $(top_builddir)/src/common/health/libhealth.la
diff --git a/src/bin/lttng-relayd/health-relayd.h b/src/bin/lttng-relayd/health-relayd.h
new file mode 100644 (file)
index 0000000..6b55cc3
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef HEALTH_RELAYD_H
+#define HEALTH_RELAYD_H
+
+/*
+ * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <lttng/health-internal.h>
+
+enum health_type {
+       HEALTH_RELAYD_TYPE_DISPATCHER           = 0,
+       HEALTH_RELAYD_TYPE_WORKER               = 1,
+       HEALTH_RELAYD_TYPE_LISTENER             = 2,
+
+       NR_HEALTH_RELAYD_TYPES,
+};
+
+#endif /* HEALTH_RELAYD_H */
index 9a68b2b2d940fc2860fbbde22c0ebc20cb89ff59..bf7be3e25c77b299e139ce8c46d49e6b8b9bb667 100644 (file)
@@ -57,6 +57,7 @@
 #include "utils.h"
 #include "lttng-relayd.h"
 #include "live.h"
+#include "health-relayd.h"
 
 /* command line options */
 char *opt_output_path;
@@ -114,6 +115,9 @@ struct lttng_ht *viewer_streams_ht;
 /* Global hash table that stores relay index object. */
 struct lttng_ht *indexes_ht;
 
+/* Relayd health monitoring */
+static struct health_app *health_relayd;
+
 /*
  * usage function on stderr
  */
@@ -513,6 +517,8 @@ void *relay_thread_listener(void *data)
 
        DBG("[thread] Relay listener started");
 
+       health_register(health_relayd, HEALTH_RELAYD_TYPE_LISTENER);
+
        control_sock = relay_init_sock(control_uri);
        if (!control_sock) {
                goto error_sock_control;
@@ -658,6 +664,7 @@ error_sock_control:
        if (err) {
                DBG("Thread exited with error");
        }
+       health_unregister(health_relayd);
        DBG("Relay listener thread cleanup complete");
        stop_threads();
        return NULL;
@@ -675,6 +682,8 @@ void *relay_thread_dispatcher(void *data)
 
        DBG("[thread] Relay dispatcher started");
 
+       health_register(health_relayd, HEALTH_RELAYD_TYPE_DISPATCHER);
+
        while (!CMM_LOAD_SHARED(dispatch_thread_exit)) {
                /* Atomically prepare the queue futex */
                futex_nto1_prepare(&relay_cmd_queue.futex);
@@ -712,6 +721,7 @@ void *relay_thread_dispatcher(void *data)
        }
 
 error:
+       health_unregister(health_relayd);
        DBG("Dispatch thread dying");
        stop_threads();
        return NULL;
@@ -2144,6 +2154,8 @@ void *relay_thread_worker(void *data)
 
        rcu_register_thread();
 
+       health_register(health_relayd, HEALTH_RELAYD_TYPE_WORKER);
+
        /* table of connections indexed on socket */
        relay_connections_ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
        if (!relay_connections_ht) {
@@ -2385,6 +2397,7 @@ relay_connections_ht_error:
        if (err) {
                DBG("Thread exited with error");
        }
+       health_unregister(health_relayd);
        DBG("Worker thread cleanup complete");
        free(data_buffer);
        stop_threads();
@@ -2503,6 +2516,13 @@ int main(int argc, char **argv)
                goto exit_relay_ctx_viewer_streams;
        }
 
+       /* Initialize thread health monitoring */
+       health_relayd = health_app_create(NR_HEALTH_RELAYD_TYPES);
+       if (!health_relayd) {
+               PERROR("health_app_create error");
+               goto exit_health_app_create;
+       }
+
        /* Setup the dispatcher thread */
        ret = pthread_create(&dispatcher_thread, NULL,
                        relay_thread_dispatcher, (void *) NULL);
@@ -2557,6 +2577,9 @@ exit_worker:
        }
 
 exit_dispatcher:
+       health_app_destroy(health_relayd);
+
+exit_health_app_create:
        lttng_ht_destroy(viewer_streams_ht);
 
 exit_relay_ctx_viewer_streams:
This page took 0.029126 seconds and 4 git commands to generate.