Commit | Line | Data |
---|---|---|
dff9583f | 1 | /* |
9d16b343 MJ |
2 | * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com> |
3 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
dff9583f | 4 | * |
9d16b343 | 5 | * SPDX-License-Identifier: GPL-2.0-only |
dff9583f | 6 | * |
dff9583f CB |
7 | */ |
8 | ||
28f23191 JG |
9 | #include <lttng/health.h> |
10 | ||
dff9583f | 11 | #include <stdio.h> |
6c71277b | 12 | #include <stdlib.h> |
4d6fd696 | 13 | #include <string.h> |
dff9583f | 14 | |
4d6fd696 MD |
15 | static const char *relayd_path; |
16 | ||
28f23191 JG |
17 | static int |
18 | check_component(struct lttng_health *lh, const char *component_name, int ok_if_not_running) | |
dff9583f | 19 | { |
6c71277b MD |
20 | const struct lttng_health_thread *thread; |
21 | int nr_threads, i, status; | |
dff9583f | 22 | |
6c71277b | 23 | if (lttng_health_query(lh)) { |
26401f03 MD |
24 | if (ok_if_not_running) { |
25 | return 0; | |
26 | } | |
28f23191 | 27 | fprintf(stderr, "Error querying %s health\n", component_name); |
6c71277b MD |
28 | return -1; |
29 | } | |
30 | status = lttng_health_state(lh); | |
31 | if (!status) { | |
32 | return status; | |
33 | } | |
dff9583f | 34 | |
6c71277b MD |
35 | nr_threads = lttng_health_get_nr_threads(lh); |
36 | if (nr_threads < 0) { | |
37 | fprintf(stderr, "Error getting number of threads\n"); | |
38 | return -1; | |
dff9583f CB |
39 | } |
40 | ||
6c71277b MD |
41 | printf("Component \"%s\" is in error.\n", component_name); |
42 | for (i = 0; i < nr_threads; i++) { | |
43 | int thread_state; | |
dff9583f | 44 | |
6c71277b MD |
45 | thread = lttng_health_get_thread(lh, i); |
46 | if (!thread) { | |
47 | fprintf(stderr, "Error getting thread %d\n", i); | |
48 | return -1; | |
49 | } | |
50 | thread_state = lttng_health_thread_state(thread); | |
51 | if (!thread_state) { | |
52 | continue; | |
53 | } | |
54 | printf("Thread \"%s\" is not responding in component \"%s\".\n", | |
28f23191 JG |
55 | lttng_health_thread_name(thread), |
56 | component_name); | |
dff9583f | 57 | } |
6c71277b MD |
58 | return status; |
59 | } | |
dff9583f | 60 | |
28f23191 | 61 | static int check_sessiond(void) |
6c71277b MD |
62 | { |
63 | struct lttng_health *lh; | |
64 | int status; | |
dff9583f | 65 | |
6c71277b MD |
66 | lh = lttng_health_create_sessiond(); |
67 | if (!lh) { | |
68 | perror("lttng_health_create_sessiond"); | |
69 | return -1; | |
dff9583f CB |
70 | } |
71 | ||
26401f03 | 72 | status = check_component(lh, "sessiond", 0); |
6c71277b MD |
73 | |
74 | lttng_health_destroy(lh); | |
75 | ||
76 | return status; | |
77 | } | |
78 | ||
28f23191 | 79 | static int check_consumerd(enum lttng_health_consumerd hc) |
6c71277b MD |
80 | { |
81 | struct lttng_health *lh; | |
82 | int status; | |
83 | static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = { | |
84 | "ust-consumerd-32", | |
85 | "ust-consumerd-64", | |
86 | "kernel-consumerd", | |
87 | }; | |
dff9583f | 88 | |
6c71277b MD |
89 | lh = lttng_health_create_consumerd(hc); |
90 | if (!lh) { | |
91 | perror("lttng_health_create_consumerd"); | |
92 | return -1; | |
dff9583f CB |
93 | } |
94 | ||
26401f03 | 95 | status = check_component(lh, cnames[hc], 1); |
6c71277b MD |
96 | |
97 | lttng_health_destroy(lh); | |
98 | ||
dff9583f CB |
99 | return status; |
100 | } | |
6c71277b | 101 | |
28f23191 | 102 | static int check_relayd(const char *path) |
4d6fd696 MD |
103 | { |
104 | struct lttng_health *lh; | |
105 | int status; | |
106 | ||
107 | lh = lttng_health_create_relayd(path); | |
108 | if (!lh) { | |
109 | perror("lttng_health_create_relayd"); | |
110 | return -1; | |
111 | } | |
112 | ||
26401f03 | 113 | status = check_component(lh, "relayd", 0); |
4d6fd696 MD |
114 | |
115 | lttng_health_destroy(lh); | |
116 | ||
117 | return status; | |
118 | } | |
6c71277b MD |
119 | |
120 | int main(int argc, char *argv[]) | |
121 | { | |
122 | int status = 0, i; | |
123 | ||
4d6fd696 | 124 | for (i = 1; i < argc; i++) { |
bd38113f | 125 | size_t relayd_path_arg_len = strlen("--relayd-path="); |
28f23191 | 126 | if (!strncmp(argv[i], "--relayd-path=", relayd_path_arg_len)) { |
bd38113f | 127 | relayd_path = &argv[i][relayd_path_arg_len]; |
4d6fd696 | 128 | } else { |
28f23191 JG |
129 | fprintf(stderr, |
130 | "Unknown option \"%s\". Try --relayd-path=PATH.\n", | |
131 | argv[i]); | |
4d6fd696 MD |
132 | exit(EXIT_FAILURE); |
133 | } | |
134 | } | |
135 | ||
6c71277b MD |
136 | status |= check_sessiond(); |
137 | for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) { | |
138 | status |= check_consumerd(i); | |
139 | } | |
4d6fd696 MD |
140 | if (relayd_path) { |
141 | status |= check_relayd(relayd_path); | |
142 | } | |
6c71277b MD |
143 | if (!status) { |
144 | exit(EXIT_SUCCESS); | |
145 | } else { | |
146 | exit(EXIT_FAILURE); | |
147 | } | |
148 | } |