2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
3 * Copyright (C) 2014 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <lttng/health.h>
25 static const char *relayd_path
;
28 int check_component(struct lttng_health
*lh
, const char *component_name
,
29 int ok_if_not_running
)
31 const struct lttng_health_thread
*thread
;
32 int nr_threads
, i
, status
;
34 if (lttng_health_query(lh
)) {
35 if (ok_if_not_running
) {
38 fprintf(stderr
, "Error querying %s health\n",
42 status
= lttng_health_state(lh
);
47 nr_threads
= lttng_health_get_nr_threads(lh
);
49 fprintf(stderr
, "Error getting number of threads\n");
53 printf("Component \"%s\" is in error.\n", component_name
);
54 for (i
= 0; i
< nr_threads
; i
++) {
57 thread
= lttng_health_get_thread(lh
, i
);
59 fprintf(stderr
, "Error getting thread %d\n", i
);
62 thread_state
= lttng_health_thread_state(thread
);
66 printf("Thread \"%s\" is not responding in component \"%s\".\n",
67 lttng_health_thread_name(thread
),
75 int check_sessiond(void)
77 struct lttng_health
*lh
;
80 lh
= lttng_health_create_sessiond();
82 perror("lttng_health_create_sessiond");
86 status
= check_component(lh
, "sessiond", 0);
88 lttng_health_destroy(lh
);
94 int check_consumerd(enum lttng_health_consumerd hc
)
96 struct lttng_health
*lh
;
98 static const char *cnames
[NR_LTTNG_HEALTH_CONSUMERD
] = {
104 lh
= lttng_health_create_consumerd(hc
);
106 perror("lttng_health_create_consumerd");
110 status
= check_component(lh
, cnames
[hc
], 1);
112 lttng_health_destroy(lh
);
118 int check_relayd(const char *path
)
120 struct lttng_health
*lh
;
123 lh
= lttng_health_create_relayd(path
);
125 perror("lttng_health_create_relayd");
129 status
= check_component(lh
, "relayd", 0);
131 lttng_health_destroy(lh
);
136 int main(int argc
, char *argv
[])
140 for (i
= 1; i
< argc
; i
++) {
141 size_t relayd_path_arg_len
= strlen("--relayd-path=");
142 if (!strncmp(argv
[i
], "--relayd-path=",
143 relayd_path_arg_len
)) {
144 relayd_path
= &argv
[i
][relayd_path_arg_len
];
146 fprintf(stderr
, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv
[i
]);
151 status
|= check_sessiond();
152 for (i
= 0; i
< NR_LTTNG_HEALTH_CONSUMERD
; i
++) {
153 status
|= check_consumerd(i
);
156 status
|= check_relayd(relayd_path
);