2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
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.
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
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.
22 #include <lttng/health.h>
24 static const char *relayd_path
;
27 int check_component(struct lttng_health
*lh
, const char *component_name
)
29 const struct lttng_health_thread
*thread
;
30 int nr_threads
, i
, status
;
32 if (lttng_health_query(lh
)) {
33 fprintf(stderr
, "Error querying %s health\n",
37 status
= lttng_health_state(lh
);
42 nr_threads
= lttng_health_get_nr_threads(lh
);
44 fprintf(stderr
, "Error getting number of threads\n");
48 printf("Component \"%s\" is in error.\n", component_name
);
49 for (i
= 0; i
< nr_threads
; i
++) {
52 thread
= lttng_health_get_thread(lh
, i
);
54 fprintf(stderr
, "Error getting thread %d\n", i
);
57 thread_state
= lttng_health_thread_state(thread
);
61 printf("Thread \"%s\" is not responding in component \"%s\".\n",
62 lttng_health_thread_name(thread
),
70 int check_sessiond(void)
72 struct lttng_health
*lh
;
75 lh
= lttng_health_create_sessiond();
77 perror("lttng_health_create_sessiond");
81 status
= check_component(lh
, "sessiond");
83 lttng_health_destroy(lh
);
89 int check_consumerd(enum lttng_health_consumerd hc
)
91 struct lttng_health
*lh
;
93 static const char *cnames
[NR_LTTNG_HEALTH_CONSUMERD
] = {
99 lh
= lttng_health_create_consumerd(hc
);
101 perror("lttng_health_create_consumerd");
105 status
= check_component(lh
, cnames
[hc
]);
107 lttng_health_destroy(lh
);
113 int check_relayd(const char *path
)
115 struct lttng_health
*lh
;
118 lh
= lttng_health_create_relayd(path
);
120 perror("lttng_health_create_relayd");
124 status
= check_component(lh
, "relayd");
126 lttng_health_destroy(lh
);
131 int main(int argc
, char *argv
[])
135 for (i
= 1; i
< argc
; i
++) {
136 if (!strcmp(argv
[i
], "--relayd-path")) {
138 fprintf(stderr
, "Missing relayd path\n");
141 relayd_path
= argv
[++i
];
143 fprintf(stderr
, "Unknown option \"%s\". Try --relayd-path PATH.\n", argv
[i
]);
148 status
|= check_sessiond();
149 for (i
= 0; i
< NR_LTTNG_HEALTH_CONSUMERD
; i
++) {
150 status
|= check_consumerd(i
);
153 status
|= check_relayd(relayd_path
);