dc975de99df6af9badc4478175b1cca1a927046a
[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 int ok_if_not_running)
29 {
30 const struct lttng_health_thread *thread;
31 int nr_threads, i, status;
32
33 if (lttng_health_query(lh)) {
34 if (ok_if_not_running) {
35 return 0;
36 }
37 fprintf(stderr, "Error querying %s health\n",
38 component_name);
39 return -1;
40 }
41 status = lttng_health_state(lh);
42 if (!status) {
43 return status;
44 }
45
46 nr_threads = lttng_health_get_nr_threads(lh);
47 if (nr_threads < 0) {
48 fprintf(stderr, "Error getting number of threads\n");
49 return -1;
50 }
51
52 printf("Component \"%s\" is in error.\n", component_name);
53 for (i = 0; i < nr_threads; i++) {
54 int thread_state;
55
56 thread = lttng_health_get_thread(lh, i);
57 if (!thread) {
58 fprintf(stderr, "Error getting thread %d\n", i);
59 return -1;
60 }
61 thread_state = lttng_health_thread_state(thread);
62 if (!thread_state) {
63 continue;
64 }
65 printf("Thread \"%s\" is not responding in component \"%s\".\n",
66 lttng_health_thread_name(thread),
67 component_name);
68
69 }
70 return status;
71 }
72
73 static
74 int check_sessiond(void)
75 {
76 struct lttng_health *lh;
77 int status;
78
79 lh = lttng_health_create_sessiond();
80 if (!lh) {
81 perror("lttng_health_create_sessiond");
82 return -1;
83 }
84
85 status = check_component(lh, "sessiond", 0);
86
87 lttng_health_destroy(lh);
88
89 return status;
90 }
91
92 static
93 int check_consumerd(enum lttng_health_consumerd hc)
94 {
95 struct lttng_health *lh;
96 int status;
97 static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = {
98 "ust-consumerd-32",
99 "ust-consumerd-64",
100 "kernel-consumerd",
101 };
102
103 lh = lttng_health_create_consumerd(hc);
104 if (!lh) {
105 perror("lttng_health_create_consumerd");
106 return -1;
107 }
108
109 status = check_component(lh, cnames[hc], 1);
110
111 lttng_health_destroy(lh);
112
113 return status;
114 }
115
116 static
117 int check_relayd(const char *path)
118 {
119 struct lttng_health *lh;
120 int status;
121
122 lh = lttng_health_create_relayd(path);
123 if (!lh) {
124 perror("lttng_health_create_relayd");
125 return -1;
126 }
127
128 status = check_component(lh, "relayd", 0);
129
130 lttng_health_destroy(lh);
131
132 return status;
133 }
134
135 int main(int argc, char *argv[])
136 {
137 int status = 0, i;
138
139 for (i = 1; i < argc; i++) {
140 size_t relayd_path_arg_len = strlen("--relayd-path=");
141 if (!strncmp(argv[i], "--relayd-path=",
142 relayd_path_arg_len)) {
143 relayd_path = &argv[i][relayd_path_arg_len];
144 } else {
145 fprintf(stderr, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv[i]);
146 exit(EXIT_FAILURE);
147 }
148 }
149
150 status |= check_sessiond();
151 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
152 status |= check_consumerd(i);
153 }
154 if (relayd_path) {
155 status |= check_relayd(relayd_path);
156 }
157 if (!status) {
158 exit(EXIT_SUCCESS);
159 } else {
160 exit(EXIT_FAILURE);
161 }
162 }
This page took 0.032869 seconds and 4 git commands to generate.