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