2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
3 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
13 #include <lttng/health.h>
15 static const char *relayd_path
;
18 int check_component(struct lttng_health
*lh
, const char *component_name
,
19 int ok_if_not_running
)
21 const struct lttng_health_thread
*thread
;
22 int nr_threads
, i
, status
;
24 if (lttng_health_query(lh
)) {
25 if (ok_if_not_running
) {
28 fprintf(stderr
, "Error querying %s health\n",
32 status
= lttng_health_state(lh
);
37 nr_threads
= lttng_health_get_nr_threads(lh
);
39 fprintf(stderr
, "Error getting number of threads\n");
43 printf("Component \"%s\" is in error.\n", component_name
);
44 for (i
= 0; i
< nr_threads
; i
++) {
47 thread
= lttng_health_get_thread(lh
, i
);
49 fprintf(stderr
, "Error getting thread %d\n", i
);
52 thread_state
= lttng_health_thread_state(thread
);
56 printf("Thread \"%s\" is not responding in component \"%s\".\n",
57 lttng_health_thread_name(thread
),
65 int check_sessiond(void)
67 struct lttng_health
*lh
;
70 lh
= lttng_health_create_sessiond();
72 perror("lttng_health_create_sessiond");
76 status
= check_component(lh
, "sessiond", 0);
78 lttng_health_destroy(lh
);
84 int check_consumerd(enum lttng_health_consumerd hc
)
86 struct lttng_health
*lh
;
88 static const char *cnames
[NR_LTTNG_HEALTH_CONSUMERD
] = {
94 lh
= lttng_health_create_consumerd(hc
);
96 perror("lttng_health_create_consumerd");
100 status
= check_component(lh
, cnames
[hc
], 1);
102 lttng_health_destroy(lh
);
108 int check_relayd(const char *path
)
110 struct lttng_health
*lh
;
113 lh
= lttng_health_create_relayd(path
);
115 perror("lttng_health_create_relayd");
119 status
= check_component(lh
, "relayd", 0);
121 lttng_health_destroy(lh
);
126 int main(int argc
, char *argv
[])
130 for (i
= 1; i
< argc
; i
++) {
131 size_t relayd_path_arg_len
= strlen("--relayd-path=");
132 if (!strncmp(argv
[i
], "--relayd-path=",
133 relayd_path_arg_len
)) {
134 relayd_path
= &argv
[i
][relayd_path_arg_len
];
136 fprintf(stderr
, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv
[i
]);
141 status
|= check_sessiond();
142 for (i
= 0; i
< NR_LTTNG_HEALTH_CONSUMERD
; i
++) {
143 status
|= check_consumerd(i
);
146 status
|= check_relayd(relayd_path
);