/*
ctdb status tool
Copyright (C) Andrew Tridgell 2007
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see .
*/
#include "includes.h"
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
#include "cmdline.h"
#include "../include/ctdb_private.h"
/*
display status structure
*/
static void show_status(struct ctdb_status *s)
{
printf(" client_packets_sent %u\n", s->client_packets_sent);
printf(" client_packets_recv %u\n", s->client_packets_recv);
printf(" req_call %u\n", s->client.req_call);
printf(" req_message %u\n", s->client.req_message);
printf(" req_finished %u\n", s->client.req_finished);
printf(" req_register %u\n", s->client.req_register);
printf(" req_connect_wait %u\n", s->client.req_connect_wait);
printf(" req_shutdown %u\n", s->client.req_shutdown);
printf(" req_status %u\n", s->client.req_status);
printf(" node_packets_sent %u\n", s->node_packets_sent);
printf(" node_packets_recv %u\n", s->node_packets_recv);
printf(" req_call %u\n", s->client.req_call);
printf(" reply_call %u\n", s->count.reply_call);
printf(" reply_redirect %u\n", s->count.reply_redirect);
printf(" req_dmaster %u\n", s->count.req_dmaster);
printf(" reply_dmaster %u\n", s->count.reply_dmaster);
printf(" reply_error %u\n", s->count.reply_error);
printf(" reply_redirect %u\n", s->count.reply_redirect);
printf(" req_message %u\n", s->count.req_message);
printf(" req_finished %u\n", s->count.req_finished);
printf(" total_calls %u\n", s->total_calls);
printf(" pending_calls %u\n", s->pending_calls);
printf(" lockwait_calls %u\n", s->lockwait_calls);
printf(" pending_lockwait_calls %u\n", s->pending_lockwait_calls);
printf(" max_call_latency %.6f seconds\n", s->max_call_latency);
printf(" max_lockwait_latency %.6f seconds\n", s->max_lockwait_latency);
}
/*
show usage message
*/
static void usage(void)
{
printf("Usage: ctdb_status \n");
exit(1);
}
/*
main program
*/
int main(int argc, const char *argv[])
{
struct ctdb_context *ctdb;
struct poptOption popt_options[] = {
POPT_AUTOHELP
POPT_CTDB_CMDLINE
POPT_TABLEEND
};
int opt;
const char **extra_argv;
int extra_argc = 0;
int ret;
poptContext pc;
struct event_context *ev;
const char *ctdb_socket;
struct ctdb_status status;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
default:
fprintf(stderr, "Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
exit(1);
}
}
/* setup the remaining options for the main program to use */
extra_argv = poptGetArgs(pc);
if (extra_argv) {
extra_argv++;
while (extra_argv[extra_argc]) extra_argc++;
}
if (extra_argc < 1) {
usage();
}
ctdb_socket = extra_argv[0];
ev = event_context_init(NULL);
/* initialise ctdb */
ctdb = ctdb_cmdline_client(ev, ctdb_socket);
if (ctdb == NULL) {
printf("Failed to init ctdb\n");
exit(1);
}
ret = ctdb_status(ctdb, &status);
if (ret != 0) {
printf("Failed to get ctdb status\n");
exit(1);
}
show_status(&status);
return 0;
}