diff --git a/Documentation/Debug And Diagnostic Support.pdf b/Documentation/Debug And Diagnostic Support.pdf index 2b848d77b..8f473c5fe 100644 Binary files a/Documentation/Debug And Diagnostic Support.pdf and b/Documentation/Debug And Diagnostic Support.pdf differ diff --git a/server/core/server.c b/server/core/server.c index 204155f5e..d80c9372a 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -279,6 +279,37 @@ char *stat; dcb_printf(dcb, "\tCurrent no. of conns: %d\n", server->stats.n_current); } +/** + * List all servers in a tabular form to a DCB + * + */ +void +dListServers(DCB *dcb) +{ +SERVER *ptr; +char *stat; + + spinlock_acquire(&server_spin); + ptr = allServers; + if (ptr) + { + dcb_printf(dcb, "%-18s | %-15s | Port | %-18s | Connections\n", + "Server", "Address", "Status"); + dcb_printf(dcb, "-------------------------------------------------------------------------------\n"); + } + while (ptr) + { + stat = server_status(ptr); + dcb_printf(dcb, "%-18s | %-15s | %5d | %-18s | %4d\n", + ptr->unique_name, ptr->name, + ptr->port, stat, + ptr->stats.n_current); + free(stat); + ptr = ptr->next; + } + spinlock_release(&server_spin); +} + /** * Convert a set of server status flags to a string, the returned * string has been malloc'd and must be free'd by the caller diff --git a/server/core/service.c b/server/core/service.c index efc441173..cb7bea457 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -726,6 +726,72 @@ SERVER *server = service->databases; dcb_printf(dcb, "\tCurrently connected: %d\n", service->stats.n_current); } +/** + * List the defined services in a tabular format. + * + * @param dcb DCB to print the service list to. + */ +void +dListServices(DCB *dcb) +{ +SERVICE *ptr; + + spinlock_acquire(&service_spin); + ptr = allServices; + if (ptr) + { + dcb_printf(dcb, "%-25s | %-20s | #Users | Total Sessions\n", + "Service Name", "Router Module"); + dcb_printf(dcb, "--------------------------------------------------------------------------\n"); + } + while (ptr) + { + dcb_printf(dcb, "%-25s | %-20s | %6d | %5d\n", + ptr->name, ptr->routerModule, + ptr->stats.n_current, ptr->stats.n_sessions); + ptr = ptr->next; + } + spinlock_release(&service_spin); +} + +/** + * List the defined listeners in a tabular format. + * + * @param dcb DCB to print the service list to. + */ +void +dListListeners(DCB *dcb) +{ +SERVICE *ptr; +SERV_PROTOCOL *lptr; + + spinlock_acquire(&service_spin); + ptr = allServices; + if (ptr) + { + dcb_printf(dcb, "%-20s | %-18s | %-15s | Port | State\n", + "Service Name", "Protocol Module", "Address"); + dcb_printf(dcb, "---------------------------------------------------------------------------\n"); + } + while (ptr) + { + lptr = ptr->ports; + while (lptr) + { + dcb_printf(dcb, "%-20s | %-18s | %-15s | %5d | %s\n", + ptr->name, lptr->protocol, + (lptr != NULL) ? lptr->address : "*", + lptr->port, + (lptr->listener->session->state == SESSION_STATE_LISTENER_STOPPED) ? "Stopped" : "Running" + ); + + lptr = lptr->next; + } + ptr = ptr->next; + } + spinlock_release(&service_spin); +} + /** * Update the definition of a service * diff --git a/server/core/session.c b/server/core/session.c index bd8188bcc..8f59b85d3 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -398,6 +398,7 @@ int norouter = 0; if (norouter) printf("%d Sessions have no router session\n", norouter); } + /** * Print all sessions to a DCB * @@ -448,6 +449,37 @@ dprintSession(DCB *dcb, SESSION *ptr) dcb_printf(dcb, "\tConnected: %s", asctime(localtime(&ptr->stats.connect))); } +/** + * List all sessions in tabular form to a DCB + * + * Designed to be called within a debugger session in order + * to display all active sessions within the gateway + * + * @param dcb The DCB to print to + */ +void +dListSessions(DCB *dcb) +{ +SESSION *ptr; + + spinlock_acquire(&session_spin); + ptr = allSessions; + if (ptr) + { + dcb_printf(dcb, "Session | Client | State\n"); + dcb_printf(dcb, "------------------------------------------\n"); + } + while (ptr) + { + dcb_printf(dcb, "%-16p | %-15s | %s\n", ptr, + ((ptr->client && ptr->client->remote) + ? ptr->client->remote : ""), + session_state(ptr->state)); + ptr = ptr->next; + } + spinlock_release(&session_spin); +} + /** * Convert a session state to a string representation * diff --git a/server/include/server.h b/server/include/server.h index dfd439852..0f093e39b 100644 --- a/server/include/server.h +++ b/server/include/server.h @@ -115,6 +115,7 @@ extern void printServer(SERVER *); extern void printAllServers(); extern void dprintAllServers(DCB *); extern void dprintServer(DCB *, SERVER *); +extern void dListServers(DCB *); extern char *server_status(SERVER *); extern void server_set_status(SERVER *, int); extern void server_clear_status(SERVER *, int); diff --git a/server/include/service.h b/server/include/service.h index 9369712f0..28ae8d3f3 100644 --- a/server/include/service.h +++ b/server/include/service.h @@ -160,4 +160,6 @@ bool service_set_slave_conn_limit ( char* valstr, count_spec_t count_spec); extern void dprintService(DCB *, SERVICE *); +extern void dListServices(DCB *); +extern void dListListeners(DCB *); #endif diff --git a/server/include/session.h b/server/include/session.h index 790922d25..3f6955ae3 100644 --- a/server/include/session.h +++ b/server/include/session.h @@ -93,6 +93,7 @@ void printAllSessions(); void printSession(SESSION *); void dprintAllSessions(struct dcb *); void dprintSession(struct dcb *, SESSION *); +void dListSessions(struct dcb *); char *session_state(int); bool session_link_dcb(SESSION *, struct dcb *); SESSION* get_session_by_router_ses(void* rses); diff --git a/server/modules/routing/debugcli.c b/server/modules/routing/debugcli.c index d6becdfda..61e308a96 100644 --- a/server/modules/routing/debugcli.c +++ b/server/modules/routing/debugcli.c @@ -45,7 +45,7 @@ extern int lm_enabled_logfiles_bitmask; -static char *version_str = "V1.1.0"; +static char *version_str = "V1.1.1"; /* The router entry points */ static ROUTER *createInstance(SERVICE *service, char **options); diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index bab8c2f55..e7720cb30 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -153,6 +153,34 @@ struct subcommand showoptions[] = { {0, 0, 0} } }; +/** + * The subcommands of the list command + */ +struct subcommand listoptions[] = { + { "listeners", 0, dListListeners, + "List all the listeners defined within MaxScale", + "List all the listeners defined within MaxScale", + {0, 0, 0} }, + { "modules", 0, dprintAllModules, + "Show all currently loaded modules", + "Show all currently loaded modules", + {0, 0, 0} }, + { "services", 0, dListServices, + "List all the services defined within MaxScale", + "List all the services defined within MaxScale", + {0, 0, 0} }, + { "servers", 0, dListServers, + "List all the servers defined within MaxScale", + "List all the servers defined within MaxScale", + {0, 0, 0} }, + { "sessions", 0, dListSessions, + "List all the active sessions within MaxScale", + "List all the active sessions within MaxScale", + {0, 0, 0} }, + { NULL, 0, NULL, NULL, NULL, + {0, 0, 0} } +}; + extern void shutdown_server(); static void shutdown_service(DCB *dcb, SERVICE *service); static void shutdown_monitor(DCB *dcb, MONITOR *monitor); @@ -396,17 +424,18 @@ static struct { } cmds[] = { { "add", addoptions }, { "clear", clearoptions }, + { "disable", disableoptions }, + { "enable", enableoptions }, +#if defined(SS_DEBUG) + { "fail", failoptions }, +#endif + { "list", listoptions }, + { "reload", reloadoptions }, { "remove", removeoptions }, { "restart", restartoptions }, { "set", setoptions }, { "show", showoptions }, { "shutdown", shutdownoptions }, - { "reload", reloadoptions }, - { "enable", enableoptions }, - { "disable", disableoptions }, -#if defined(SS_DEBUG) - { "fail", failoptions }, -#endif { NULL, NULL } }; @@ -488,7 +517,6 @@ execute_cmd(CLI_SESSION *cli) DCB *dcb = cli->session->client; int argc, i, j, found = 0; char *args[MAXARGS]; -char *saveptr, *delim = " \t\r\n"; unsigned long arg1, arg2, arg3; int in_quotes = 0, escape_next = 0; char *ptr, *lptr;