health check tests: test relayd and consumerd
[lttng-tools.git] / tests / regression / tools / health / health_check.c
CommitLineData
dff9583f
CB
1/*
2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
a33d2d4a 3 * Copyright (C) 2014 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
dff9583f
CB
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <stdio.h>
6c71277b 20#include <stdlib.h>
4d6fd696 21#include <string.h>
dff9583f 22
6c71277b 23#include <lttng/health.h>
dff9583f 24
4d6fd696
MD
25static const char *relayd_path;
26
6c71277b 27static
26401f03
MD
28int check_component(struct lttng_health *lh, const char *component_name,
29 int ok_if_not_running)
dff9583f 30{
6c71277b
MD
31 const struct lttng_health_thread *thread;
32 int nr_threads, i, status;
dff9583f 33
6c71277b 34 if (lttng_health_query(lh)) {
26401f03
MD
35 if (ok_if_not_running) {
36 return 0;
37 }
6c71277b
MD
38 fprintf(stderr, "Error querying %s health\n",
39 component_name);
40 return -1;
41 }
42 status = lttng_health_state(lh);
43 if (!status) {
44 return status;
45 }
dff9583f 46
6c71277b
MD
47 nr_threads = lttng_health_get_nr_threads(lh);
48 if (nr_threads < 0) {
49 fprintf(stderr, "Error getting number of threads\n");
50 return -1;
dff9583f
CB
51 }
52
6c71277b
MD
53 printf("Component \"%s\" is in error.\n", component_name);
54 for (i = 0; i < nr_threads; i++) {
55 int thread_state;
dff9583f 56
6c71277b
MD
57 thread = lttng_health_get_thread(lh, i);
58 if (!thread) {
59 fprintf(stderr, "Error getting thread %d\n", i);
60 return -1;
61 }
62 thread_state = lttng_health_thread_state(thread);
63 if (!thread_state) {
64 continue;
65 }
66 printf("Thread \"%s\" is not responding in component \"%s\".\n",
67 lttng_health_thread_name(thread),
68 component_name);
dff9583f 69
dff9583f 70 }
6c71277b
MD
71 return status;
72}
dff9583f 73
6c71277b
MD
74static
75int check_sessiond(void)
76{
77 struct lttng_health *lh;
78 int status;
dff9583f 79
6c71277b
MD
80 lh = lttng_health_create_sessiond();
81 if (!lh) {
82 perror("lttng_health_create_sessiond");
83 return -1;
dff9583f
CB
84 }
85
26401f03 86 status = check_component(lh, "sessiond", 0);
6c71277b
MD
87
88 lttng_health_destroy(lh);
89
90 return status;
91}
92
93static
94int check_consumerd(enum lttng_health_consumerd hc)
95{
96 struct lttng_health *lh;
97 int status;
98 static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = {
99 "ust-consumerd-32",
100 "ust-consumerd-64",
101 "kernel-consumerd",
102 };
dff9583f 103
6c71277b
MD
104 lh = lttng_health_create_consumerd(hc);
105 if (!lh) {
106 perror("lttng_health_create_consumerd");
107 return -1;
dff9583f
CB
108 }
109
26401f03 110 status = check_component(lh, cnames[hc], 1);
6c71277b
MD
111
112 lttng_health_destroy(lh);
113
dff9583f
CB
114 return status;
115}
6c71277b 116
4d6fd696
MD
117static
118int check_relayd(const char *path)
119{
120 struct lttng_health *lh;
121 int status;
122
123 lh = lttng_health_create_relayd(path);
124 if (!lh) {
125 perror("lttng_health_create_relayd");
126 return -1;
127 }
128
26401f03 129 status = check_component(lh, "relayd", 0);
4d6fd696
MD
130
131 lttng_health_destroy(lh);
132
133 return status;
134}
6c71277b
MD
135
136int main(int argc, char *argv[])
137{
138 int status = 0, i;
139
4d6fd696 140 for (i = 1; i < argc; i++) {
bd38113f
MD
141 size_t relayd_path_arg_len = strlen("--relayd-path=");
142 if (!strncmp(argv[i], "--relayd-path=",
143 relayd_path_arg_len)) {
144 relayd_path = &argv[i][relayd_path_arg_len];
4d6fd696 145 } else {
bd38113f 146 fprintf(stderr, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv[i]);
4d6fd696
MD
147 exit(EXIT_FAILURE);
148 }
149 }
150
6c71277b
MD
151 status |= check_sessiond();
152 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
153 status |= check_consumerd(i);
154 }
4d6fd696
MD
155 if (relayd_path) {
156 status |= check_relayd(relayd_path);
157 }
6c71277b
MD
158 if (!status) {
159 exit(EXIT_SUCCESS);
160 } else {
161 exit(EXIT_FAILURE);
162 }
163}
This page took 0.038398 seconds and 5 git commands to generate.