From 854d7d7c6889258c3e2bded7ad4785520234d0e3 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 19 May 2014 12:30:53 +0100 Subject: [PATCH] Updated debug command plugin. --- server/core/service.c | 52 +++++++++++++++++++------------ server/include/service.h | 1 + server/modules/routing/debugcmd.c | 15 +++++++-- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/server/core/service.c b/server/core/service.c index 5b681c42b..e44b9c697 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -643,7 +643,7 @@ SERVICE *ptr; /** * Print all services to a DCB * - * Designed to be called within a debugger session in order + * Designed to be called within a CLI command in order * to display all active services within the gateway */ void @@ -655,30 +655,42 @@ SERVICE *ptr; ptr = allServices; while (ptr) { - SERVER *server = ptr->databases; - dcb_printf(dcb, "Service %p\n", ptr); - dcb_printf(dcb, "\tService: %s\n", ptr->name); - dcb_printf(dcb, "\tRouter: %s (%p)\n", ptr->routerModule, - ptr->router); - if (ptr->router) - ptr->router->diagnostics(ptr->router_instance, dcb); - dcb_printf(dcb, "\tStarted: %s", - asctime(localtime(&ptr->stats.started))); - dcb_printf(dcb, "\tBackend databases\n"); - while (server) - { - dcb_printf(dcb, "\t\t%s:%d Protocol: %s\n", server->name, server->port, - server->protocol); - server = server->nextdb; - } - dcb_printf(dcb, "\tUsers data: %p\n", ptr->users); - dcb_printf(dcb, "\tTotal connections: %d\n", ptr->stats.n_sessions); - dcb_printf(dcb, "\tCurrently connected: %d\n", ptr->stats.n_current); + dprintService(dcb, ptr); ptr = ptr->next; } spinlock_release(&service_spin); } +/** + * Print details of a single service. + * + * @param dcb DCB to print data to + * @param service The service to print + */ +dprintService(DCB *dcb, SERVICE *service) +{ +SERVER *server = service->databases; + + dcb_printf(dcb, "Service %p\n", service); + dcb_printf(dcb, "\tService: %s\n", service->name); + dcb_printf(dcb, "\tRouter: %s (%p)\n", service->routerModule, + service->router); + if (service->router) + service->router->diagnostics(service->router_instance, dcb); + dcb_printf(dcb, "\tStarted: %s", + asctime(localtime(&service->stats.started))); + dcb_printf(dcb, "\tBackend databases\n"); + while (server) + { + dcb_printf(dcb, "\t\t%s:%d Protocol: %s\n", server->name, server->port, + server->protocol); + server = server->nextdb; + } + dcb_printf(dcb, "\tUsers data: %p\n", service->users); + dcb_printf(dcb, "\tTotal connections: %d\n", service->stats.n_sessions); + dcb_printf(dcb, "\tCurrently connected: %d\n", service->stats.n_current); +} + /** * Update the definition of a service * diff --git a/server/include/service.h b/server/include/service.h index 0a8db9ea2..85fe3972d 100644 --- a/server/include/service.h +++ b/server/include/service.h @@ -148,4 +148,5 @@ extern int service_refresh_users(SERVICE *); extern void printService(SERVICE *); extern void printAllServices(); extern void dprintAllServices(DCB *); +extern void dprintService(DCB *, SERVICE *); #endif diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index 422113d6c..bf3aa888b 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -68,6 +68,7 @@ #define ARG_TYPE_ADDRESS 1 #define ARG_TYPE_STRING 2 +#define ARG_TYPE_SERVICE 3 /** * The subcommand structure * @@ -104,6 +105,8 @@ struct subcommand showoptions[] = { {0, 0, 0} }, { "services", 0, dprintAllServices, "Show all configured services in MaxScale", {0, 0, 0} }, + { "service", 1, dprintService, "Show single service in MaxScale", + {ARG_TYPE_SERVICE, 0, 0} }, { "session", 1, dprintSession, "Show a single session in MaxScale, e.g. show session 0x284830", {ARG_TYPE_ADDRESS, 0, 0} }, { "sessions", 0, dprintAllSessions, "Show all active sessions in MaxScale", @@ -141,7 +144,7 @@ struct subcommand shutdownoptions[] = { 1, shutdown_service, "Shutdown a service, e.g. shutdown service 0x4838320", - {ARG_TYPE_ADDRESS, 0, 0} + {ARG_TYPE_SERVICE, 0, 0} }, { NULL, @@ -161,8 +164,8 @@ static void restart_monitor(DCB *dcb, MONITOR *monitor); struct subcommand restartoptions[] = { { "monitor", 1, restart_monitor, "Restart a monitor, e.g. restart monitor 0x48181e0", {ARG_TYPE_ADDRESS, 0, 0} }, - { "service", 1, restart_service, "Restart a service, e.g. restart service 0x4838320", - {ARG_TYPE_ADDRESS, 0, 0} }, + { "service", 1, restart_service, "Restart a service, e.g. restart service name", + {ARG_TYPE_SERVICE, 0, 0} }, { NULL, 0, NULL, NULL, {0, 0, 0} } }; @@ -355,8 +358,14 @@ static struct { static unsigned long convert_arg(char *arg, int arg_type) { +unsigned long rval; + switch (arg_type) { + case ARG_TYPE_SERVICE: + if ((rval = (unsigned long)strtol(arg, NULL, 0)) == 0) + rval = (unsigned long)service_find(arg); + return rval; case ARG_TYPE_ADDRESS: return (unsigned long)strtol(arg, NULL, 0); case ARG_TYPE_STRING: