From a022775342603fa3966004dcb6e45b160d84cbbb Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 20 Feb 2015 11:53:47 +0000 Subject: [PATCH] Addition of show eventtimes and /events/times URL to maxinfo --- server/core/poll.c | 67 +++++++++++++++++++ server/include/poll.h | 2 + server/modules/routing/maxinfo/maxinfo.c | 5 ++ server/modules/routing/maxinfo/maxinfo_exec.c | 33 +++++++-- 4 files changed, 100 insertions(+), 7 deletions(-) diff --git a/server/core/poll.c b/server/core/poll.c index a581ed773..bad9cfc52 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -33,6 +33,7 @@ #include #include #include +#include #define PROFILE_POLL 0 @@ -1561,3 +1562,69 @@ poll_get_stat(POLL_STAT stat) } return 0; } + +/** + * Provide a row to the result set that defines the event queue statistics + * + * @param set The result set + * @param data The index of the row to send + * @return The next row or NULL + */ +static RESULT_ROW * +eventTimesRowCallback(RESULTSET *set, void *data) +{ +int *rowno = (int *)data; +char buf[40]; +RESULT_ROW *row; + + if (*rowno >= N_QUEUE_TIMES) + { + free(data); + return NULL; + } + row = resultset_make_row(set); + if (*rowno == 0) + resultset_row_set(row, 0, "< 100ms"); + else if (*rowno == N_QUEUE_TIMES - 1) + { + sprintf(buf, "> %2d00ms", N_QUEUE_TIMES); + resultset_row_set(row, 0, buf); + } + else + { + sprintf(buf, "%2d00 - %2d00ms", *rowno, (*rowno) + 1); + resultset_row_set(row, 0, buf); + } + sprintf(buf, "%d", queueStats.qtimes[*rowno]); + resultset_row_set(row, 1, buf); + sprintf(buf, "%d", queueStats.exectimes[*rowno]); + resultset_row_set(row, 2, buf); + (*rowno)++; + return row; +} + +/** + * Return a resultset that has the current set of services in it + * + * @return A Result set + */ +RESULTSET * +eventTimesGetList() +{ +RESULTSET *set; +int *data; + + if ((data = (int *)malloc(sizeof(int))) == NULL) + return NULL; + *data = 0; + if ((set = resultset_create(eventTimesRowCallback, data)) == NULL) + { + free(data); + return NULL; + } + resultset_add_column(set, "Duration", 20, COL_TYPE_VARCHAR); + resultset_add_column(set, "No. Events Queued", 12, COL_TYPE_VARCHAR); + resultset_add_column(set, "No. Events Executed", 12, COL_TYPE_VARCHAR); + + return set; +} diff --git a/server/include/poll.h b/server/include/poll.h index 4030feeb1..e778c580c 100644 --- a/server/include/poll.h +++ b/server/include/poll.h @@ -19,6 +19,7 @@ */ #include #include +#include /** * @file poll.h The poll related functionality @@ -63,4 +64,5 @@ void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); extern void dShowEventQ(DCB *dcb); extern void dShowEventStats(DCB *dcb); extern int poll_get_stat(POLL_STAT stat); +extern RESULTSET *eventTimesGetList(); #endif diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.c index 7ccbcba2a..63d058ccd 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.c @@ -666,6 +666,10 @@ PARSE_ERROR err; typedef RESULTSET *(*RESULTSETFUNC)(); +/** + * Table that maps a URI to a function to call to + * to obtain the result set related to that URI + */ static struct uri_table { char *uri; RESULTSETFUNC func; @@ -678,6 +682,7 @@ static struct uri_table { { "/servers", serverGetList }, { "/variables", maxinfo_variables }, { "/status", maxinfo_status }, + { "/event/times", eventTimesGetList }, { NULL, NULL } }; diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index d3941525a..ab91c6299 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -91,7 +91,7 @@ maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree) * Fetch the list of services and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_services(DCB *dcb, MAXINFO_TREE *tree) @@ -109,7 +109,7 @@ RESULTSET *set; * Fetch the list of listeners and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_listeners(DCB *dcb, MAXINFO_TREE *tree) @@ -127,7 +127,7 @@ RESULTSET *set; * Fetch the list of sessions and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_sessions(DCB *dcb, MAXINFO_TREE *tree) @@ -145,7 +145,7 @@ RESULTSET *set; * Fetch the list of client sessions and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_clients(DCB *dcb, MAXINFO_TREE *tree) @@ -163,7 +163,7 @@ RESULTSET *set; * Fetch the list of servers and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_servers(DCB *dcb, MAXINFO_TREE *tree) @@ -181,7 +181,7 @@ RESULTSET *set; * Fetch the list of modules and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_modules(DCB *dcb, MAXINFO_TREE *tree) @@ -199,7 +199,7 @@ RESULTSET *set; * Fetch the list of monitors and stream as a result set * * @param dcb DCB to which to stream result set - * @param tree Potential liek clause (currently unused) + * @param tree Potential like clause (currently unused) */ static void exec_show_monitors(DCB *dcb, MAXINFO_TREE *tree) @@ -213,6 +213,24 @@ RESULTSET *set; resultset_free(set); } +/** + * Fetch the event times data + * + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) + */ +static void +exec_show_eventTimes(DCB *dcb, MAXINFO_TREE *tree) +{ +RESULTSET *set; + + if ((set = eventTimesGetList()) == NULL) + return; + + resultset_stream_mysql(set, dcb); + resultset_free(set); +} + /** * The table of show commands that are supported */ @@ -229,6 +247,7 @@ static struct { { "servers", exec_show_servers }, { "modules", exec_show_modules }, { "monitors", exec_show_monitors }, + { "eventTimes", exec_show_eventTimes }, { NULL, NULL } };