Health check: implement health check query in sessiond and consumerd
[lttng-tools.git] / tests / regression / tools / health / health_check.c
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>
19 #include <stdlib.h>
20
21 #include <lttng/health.h>
22
23 static
24 int check_component(struct lttng_health *lh, const char *component_name)
25 {
26 const struct lttng_health_thread *thread;
27 int nr_threads, i, status;
28
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 }
38
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;
43 }
44
45 printf("Component \"%s\" is in error.\n", component_name);
46 for (i = 0; i < nr_threads; i++) {
47 int thread_state;
48
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);
61
62 }
63 return status;
64 }
65
66 static
67 int check_sessiond(void)
68 {
69 struct lttng_health *lh;
70 int status;
71
72 lh = lttng_health_create_sessiond();
73 if (!lh) {
74 perror("lttng_health_create_sessiond");
75 return -1;
76 }
77
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 };
95
96 lh = lttng_health_create_consumerd(hc);
97 if (!lh) {
98 perror("lttng_health_create_consumerd");
99 return -1;
100 }
101
102 status = check_component(lh, cnames[hc]);
103
104 lttng_health_destroy(lh);
105
106 return status;
107 }
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 }
This page took 0.031331 seconds and 4 git commands to generate.