2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <lttng/health.h>
24 static const char *relayd_path
;
27 int check_component(struct lttng_health
*lh
, const char *component_name
,
28 int ok_if_not_running
)
30 const struct lttng_health_thread
*thread
;
31 int nr_threads
, i
, status
;
33 if (lttng_health_query(lh
)) {
34 if (ok_if_not_running
) {
37 fprintf(stderr
, "Error querying %s health\n",
41 status
= lttng_health_state(lh
);
46 nr_threads
= lttng_health_get_nr_threads(lh
);
48 fprintf(stderr
, "Error getting number of threads\n");
52 printf("Component \"%s\" is in error.\n", component_name
);
53 for (i
= 0; i
< nr_threads
; i
++) {
56 thread
= lttng_health_get_thread(lh
, i
);
58 fprintf(stderr
, "Error getting thread %d\n", i
);
61 thread_state
= lttng_health_thread_state(thread
);
65 printf("Thread \"%s\" is not responding in component \"%s\".\n",
66 lttng_health_thread_name(thread
),
74 int check_sessiond(void)
76 struct lttng_health
*lh
;
79 lh
= lttng_health_create_sessiond();
81 perror("lttng_health_create_sessiond");
85 status
= check_component(lh
, "sessiond", 0);
87 lttng_health_destroy(lh
);
93 int check_consumerd(enum lttng_health_consumerd hc
)
95 struct lttng_health
*lh
;
97 static const char *cnames
[NR_LTTNG_HEALTH_CONSUMERD
] = {
103 lh
= lttng_health_create_consumerd(hc
);
105 perror("lttng_health_create_consumerd");
109 status
= check_component(lh
, cnames
[hc
], 1);
111 lttng_health_destroy(lh
);
117 int check_relayd(const char *path
)
119 struct lttng_health
*lh
;
122 lh
= lttng_health_create_relayd(path
);
124 perror("lttng_health_create_relayd");
128 status
= check_component(lh
, "relayd", 0);
130 lttng_health_destroy(lh
);
135 int main(int argc
, char *argv
[])
139 for (i
= 1; i
< argc
; i
++) {
140 size_t relayd_path_arg_len
= strlen("--relayd-path=");
141 if (!strncmp(argv
[i
], "--relayd-path=",
142 relayd_path_arg_len
)) {
143 relayd_path
= &argv
[i
][relayd_path_arg_len
];
145 fprintf(stderr
, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv
[i
]);
150 status
|= check_sessiond();
151 for (i
= 0; i
< NR_LTTNG_HEALTH_CONSUMERD
; i
++) {
152 status
|= check_consumerd(i
);
155 status
|= check_relayd(relayd_path
);