r23798: updated old Temple Place FSF addresses to new URL
[kamenim/samba.git] / source4 / cluster / ctdb / tools / ctdb_status.c
1 /* 
2    ctdb status tool
3
4    Copyright (C) Andrew Tridgell  2007
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 3 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "lib/events/events.h"
22 #include "system/filesys.h"
23 #include "popt.h"
24 #include "cmdline.h"
25 #include "../include/ctdb_private.h"
26
27
28 /*
29   display status structure
30  */
31 static void show_status(struct ctdb_status *s)
32 {
33         printf(" client_packets_sent     %u\n", s->client_packets_sent);
34         printf(" client_packets_recv     %u\n", s->client_packets_recv);
35         printf("   req_call              %u\n", s->client.req_call);
36         printf("   req_message           %u\n", s->client.req_message);
37         printf("   req_finished          %u\n", s->client.req_finished);
38         printf("   req_register          %u\n", s->client.req_register);
39         printf("   req_connect_wait      %u\n", s->client.req_connect_wait);
40         printf("   req_shutdown          %u\n", s->client.req_shutdown);
41         printf("   req_status            %u\n", s->client.req_status);
42         printf(" node_packets_sent       %u\n", s->node_packets_sent);
43         printf(" node_packets_recv       %u\n", s->node_packets_recv);
44         printf("   req_call              %u\n", s->client.req_call);
45         printf("   reply_call            %u\n", s->count.reply_call);
46         printf("   reply_redirect        %u\n", s->count.reply_redirect);
47         printf("   req_dmaster           %u\n", s->count.req_dmaster);
48         printf("   reply_dmaster         %u\n", s->count.reply_dmaster);
49         printf("   reply_error           %u\n", s->count.reply_error);
50         printf("   reply_redirect        %u\n", s->count.reply_redirect);
51         printf("   req_message           %u\n", s->count.req_message);
52         printf("   req_finished          %u\n", s->count.req_finished);
53         printf(" total_calls             %u\n", s->total_calls);
54         printf(" pending_calls           %u\n", s->pending_calls);
55         printf(" lockwait_calls          %u\n", s->lockwait_calls);
56         printf(" pending_lockwait_calls  %u\n", s->pending_lockwait_calls);
57         printf(" max_call_latency        %.6f seconds\n", s->max_call_latency);
58         printf(" max_lockwait_latency    %.6f seconds\n", s->max_lockwait_latency);
59 }
60
61 /*
62   show usage message
63  */
64 static void usage(void)
65 {
66         printf("Usage: ctdb_status <socketpath>\n");
67         exit(1);
68 }
69
70 /*
71   main program
72 */
73 int main(int argc, const char *argv[])
74 {
75         struct ctdb_context *ctdb;
76         struct poptOption popt_options[] = {
77                 POPT_AUTOHELP
78                 POPT_CTDB_CMDLINE
79                 POPT_TABLEEND
80         };
81         int opt;
82         const char **extra_argv;
83         int extra_argc = 0;
84         int ret;
85         poptContext pc;
86         struct event_context *ev;
87         const char *ctdb_socket;
88         struct ctdb_status status;
89
90         pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
91
92         while ((opt = poptGetNextOpt(pc)) != -1) {
93                 switch (opt) {
94                 default:
95                         fprintf(stderr, "Invalid option %s: %s\n", 
96                                 poptBadOption(pc, 0), poptStrerror(opt));
97                         exit(1);
98                 }
99         }
100
101         /* setup the remaining options for the main program to use */
102         extra_argv = poptGetArgs(pc);
103         if (extra_argv) {
104                 extra_argv++;
105                 while (extra_argv[extra_argc]) extra_argc++;
106         }
107
108         if (extra_argc < 1) {
109                 usage();
110         }
111
112         ctdb_socket = extra_argv[0];
113
114         ev = event_context_init(NULL);
115
116         /* initialise ctdb */
117         ctdb = ctdb_cmdline_client(ev, ctdb_socket);
118         if (ctdb == NULL) {
119                 printf("Failed to init ctdb\n");
120                 exit(1);
121         }
122
123         ret = ctdb_status(ctdb, &status);
124         if (ret != 0) {
125                 printf("Failed to get ctdb status\n");
126                 exit(1);
127         }
128
129         show_status(&status);
130
131         return 0;
132 }