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> |
dff9583f | 20 | |
6c71277b | 21 | #include <lttng/health.h> |
dff9583f | 22 | |
6c71277b MD |
23 | static |
24 | int check_component(struct lttng_health *lh, const char *component_name) | |
dff9583f | 25 | { |
6c71277b MD |
26 | const struct lttng_health_thread *thread; |
27 | int nr_threads, i, status; | |
dff9583f | 28 | |
6c71277b MD |
29 | if (lttng_health_query(lh)) { |
30 | fprintf(stderr, "Error querying %s health\n", | |
31 | component_name); | |
32 | return -1; | |
33 | } | |
34 | status = lttng_health_state(lh); | |
35 | if (!status) { | |
36 | return status; | |
37 | } | |
dff9583f | 38 | |
6c71277b MD |
39 | nr_threads = lttng_health_get_nr_threads(lh); |
40 | if (nr_threads < 0) { | |
41 | fprintf(stderr, "Error getting number of threads\n"); | |
42 | return -1; | |
dff9583f CB |
43 | } |
44 | ||
6c71277b MD |
45 | printf("Component \"%s\" is in error.\n", component_name); |
46 | for (i = 0; i < nr_threads; i++) { | |
47 | int thread_state; | |
dff9583f | 48 | |
6c71277b MD |
49 | thread = lttng_health_get_thread(lh, i); |
50 | if (!thread) { | |
51 | fprintf(stderr, "Error getting thread %d\n", i); | |
52 | return -1; | |
53 | } | |
54 | thread_state = lttng_health_thread_state(thread); | |
55 | if (!thread_state) { | |
56 | continue; | |
57 | } | |
58 | printf("Thread \"%s\" is not responding in component \"%s\".\n", | |
59 | lttng_health_thread_name(thread), | |
60 | component_name); | |
dff9583f | 61 | |
dff9583f | 62 | } |
6c71277b MD |
63 | return status; |
64 | } | |
dff9583f | 65 | |
6c71277b MD |
66 | static |
67 | int check_sessiond(void) | |
68 | { | |
69 | struct lttng_health *lh; | |
70 | int status; | |
dff9583f | 71 | |
6c71277b MD |
72 | lh = lttng_health_create_sessiond(); |
73 | if (!lh) { | |
74 | perror("lttng_health_create_sessiond"); | |
75 | return -1; | |
dff9583f CB |
76 | } |
77 | ||
6c71277b MD |
78 | status = check_component(lh, "sessiond"); |
79 | ||
80 | lttng_health_destroy(lh); | |
81 | ||
82 | return status; | |
83 | } | |
84 | ||
85 | static | |
86 | int check_consumerd(enum lttng_health_consumerd hc) | |
87 | { | |
88 | struct lttng_health *lh; | |
89 | int status; | |
90 | static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = { | |
91 | "ust-consumerd-32", | |
92 | "ust-consumerd-64", | |
93 | "kernel-consumerd", | |
94 | }; | |
dff9583f | 95 | |
6c71277b MD |
96 | lh = lttng_health_create_consumerd(hc); |
97 | if (!lh) { | |
98 | perror("lttng_health_create_consumerd"); | |
99 | return -1; | |
dff9583f CB |
100 | } |
101 | ||
6c71277b MD |
102 | status = check_component(lh, cnames[hc]); |
103 | ||
104 | lttng_health_destroy(lh); | |
105 | ||
dff9583f CB |
106 | return status; |
107 | } | |
6c71277b MD |
108 | |
109 | ||
110 | int main(int argc, char *argv[]) | |
111 | { | |
112 | int status = 0, i; | |
113 | ||
114 | status |= check_sessiond(); | |
115 | for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) { | |
116 | status |= check_consumerd(i); | |
117 | } | |
118 | if (!status) { | |
119 | exit(EXIT_SUCCESS); | |
120 | } else { | |
121 | exit(EXIT_FAILURE); | |
122 | } | |
123 | } |