Health check test: add relayd check support
[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 #include <string.h>
21
22 #include <lttng/health.h>
23
24 static const char *relayd_path;
25
26 static
27 int check_component(struct lttng_health *lh, const char *component_name)
28 {
29 const struct lttng_health_thread *thread;
30 int nr_threads, i, status;
31
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 }
41
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;
46 }
47
48 printf("Component \"%s\" is in error.\n", component_name);
49 for (i = 0; i < nr_threads; i++) {
50 int thread_state;
51
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);
64
65 }
66 return status;
67 }
68
69 static
70 int check_sessiond(void)
71 {
72 struct lttng_health *lh;
73 int status;
74
75 lh = lttng_health_create_sessiond();
76 if (!lh) {
77 perror("lttng_health_create_sessiond");
78 return -1;
79 }
80
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 };
98
99 lh = lttng_health_create_consumerd(hc);
100 if (!lh) {
101 perror("lttng_health_create_consumerd");
102 return -1;
103 }
104
105 status = check_component(lh, cnames[hc]);
106
107 lttng_health_destroy(lh);
108
109 return status;
110 }
111
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 }
130
131 int main(int argc, char *argv[])
132 {
133 int status = 0, i;
134
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
148 status |= check_sessiond();
149 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
150 status |= check_consumerd(i);
151 }
152 if (relayd_path) {
153 status |= check_relayd(relayd_path);
154 }
155 if (!status) {
156 exit(EXIT_SUCCESS);
157 } else {
158 exit(EXIT_FAILURE);
159 }
160 }
This page took 0.035081 seconds and 6 git commands to generate.