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