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
9 #include <lttng/health.h>
15 static const char *relayd_path
;
18 check_component(struct lttng_health
*lh
, const char *component_name
, int ok_if_not_running
)
20 const struct lttng_health_thread
*thread
;
21 int nr_threads
, i
, status
;
23 if (lttng_health_query(lh
)) {
24 if (ok_if_not_running
) {
27 fprintf(stderr
, "Error querying %s health\n", component_name
);
30 status
= lttng_health_state(lh
);
35 nr_threads
= lttng_health_get_nr_threads(lh
);
37 fprintf(stderr
, "Error getting number of threads\n");
41 printf("Component \"%s\" is in error.\n", component_name
);
42 for (i
= 0; i
< nr_threads
; i
++) {
45 thread
= lttng_health_get_thread(lh
, i
);
47 fprintf(stderr
, "Error getting thread %d\n", i
);
50 thread_state
= lttng_health_thread_state(thread
);
54 printf("Thread \"%s\" is not responding in component \"%s\".\n",
55 lttng_health_thread_name(thread
),
61 static int check_sessiond(void)
63 struct lttng_health
*lh
;
66 lh
= lttng_health_create_sessiond();
68 perror("lttng_health_create_sessiond");
72 status
= check_component(lh
, "sessiond", 0);
74 lttng_health_destroy(lh
);
79 static int check_consumerd(enum lttng_health_consumerd hc
)
81 struct lttng_health
*lh
;
83 static const char *cnames
[NR_LTTNG_HEALTH_CONSUMERD
] = {
89 lh
= lttng_health_create_consumerd(hc
);
91 perror("lttng_health_create_consumerd");
95 status
= check_component(lh
, cnames
[hc
], 1);
97 lttng_health_destroy(lh
);
102 static int check_relayd(const char *path
)
104 struct lttng_health
*lh
;
107 lh
= lttng_health_create_relayd(path
);
109 perror("lttng_health_create_relayd");
113 status
= check_component(lh
, "relayd", 0);
115 lttng_health_destroy(lh
);
120 int main(int argc
, char *argv
[])
124 for (i
= 1; i
< argc
; i
++) {
125 size_t relayd_path_arg_len
= strlen("--relayd-path=");
126 if (!strncmp(argv
[i
], "--relayd-path=", relayd_path_arg_len
)) {
127 relayd_path
= &argv
[i
][relayd_path_arg_len
];
130 "Unknown option \"%s\". Try --relayd-path=PATH.\n",
136 status
|= check_sessiond();
137 for (i
= 0; i
< NR_LTTNG_HEALTH_CONSUMERD
; i
++) {
138 status
|= check_consumerd(i
);
141 status
|= check_relayd(relayd_path
);