From 798dd6a5a6616f404b366400583ea3ea58173986 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Wed, 28 May 2014 11:51:58 +0200 Subject: [PATCH] Added routines for interval and defaultId (MySQL) Added routines for interval and defaultId (MySQL) --- server/core/monitor.c | 35 ++++++++++++++++++++++-- server/include/monitor.h | 11 +++++--- server/modules/monitor/galera_mon.c | 24 ++++++++++++++--- server/modules/monitor/mysql_mon.c | 42 ++++++++++++++++++++++++++--- server/modules/monitor/mysqlmon.h | 4 +++ 5 files changed, 104 insertions(+), 12 deletions(-) diff --git a/server/core/monitor.c b/server/core/monitor.c index cee2f2d9e..236d45724 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -22,8 +22,10 @@ * @verbatim * Revision History * - * Date Who Description - * 08/07/13 Mark Riddoch Initial implementation + * Date Who Description + * 08/07/13 Mark Riddoch Initial implementation + * 23/05/14 Massimiliano Pinto Addition of monitor_interval parameter + * and monitor id * * @endverbatim */ @@ -220,3 +222,32 @@ MONITOR *ptr; spinlock_release(&monLock); return ptr; } + + +/** + * Set the id of the monitor. + * + * @param mon The monitor instance + * @param id The id for the monitor + */ + +void +monitorSetId(MONITOR *mon, unsigned long id) +{ + if (mon->module->defaultId != NULL) { + mon->module->defaultId(mon->handle, id); + } +} + +/** + * Set the monitor sampling interval. + * + * @param mon The monitor instance + * @param interval The sampling interval in milliseconds + */ +monitorSetInterval (MONITOR *mon, unsigned long interval) +{ + if (mon->module->setInterval != NULL) { + mon->module->setInterval(mon->handle, interval); + } +} diff --git a/server/include/monitor.h b/server/include/monitor.h index 6444fecd5..c09608064 100644 --- a/server/include/monitor.h +++ b/server/include/monitor.h @@ -26,10 +26,11 @@ * @verbatim * Revision History * - * Date Who Description - * 07/07/13 Mark Riddoch Initial implementation - * 25/07/13 Mark Riddoch Addition of diagnotics - * 23/05/14 Mark Riddoch Addition of routine to find monitors by name + * Date Who Description + * 07/07/13 Mark Riddoch Initial implementation + * 25/07/13 Mark Riddoch Addition of diagnotics + * 23/05/14 Mark Riddoch Addition of routine to find monitors by name + * 23/05/14 Massimiliano Pinto Addition of defaultId and setInterval * * @endverbatim */ @@ -66,6 +67,8 @@ typedef struct { void (*unregisterServer)(void *, SERVER *); void (*defaultUser)(void *, char *, char *); void (*diagnostics)(DCB *, void *); + void (*setInterval)(void *, unsigned long); + void (*defaultId)(void *, unsigned long); } MONITOR_OBJECT; /** diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index 96b891d58..4e0fd9d5b 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -26,6 +26,8 @@ * 22/07/13 Mark Riddoch Initial implementation * 21/05/14 Massimiliano Pinto Monitor sets a master server * that has the lowest value of wsrep_local_index + * 23/05/14 Massimiliano Pinto Added 1 configuration option (setInterval). + * Interval is printed in diagnostics. * * @endverbatim */ @@ -47,7 +49,7 @@ extern int lm_enabled_logfiles_bitmask; static void monitorMain(void *); -static char *version_str = "V1.1.0"; +static char *version_str = "V1.1.1"; static void *startMonitor(void *); static void stopMonitor(void *); @@ -55,8 +57,9 @@ static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); static void defaultUsers(void *, char *, char *); static void diagnostics(DCB *, void *); +static void setInterval(void *, unsigned long); -static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics }; +static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics, setInterval, NULL }; /** * Implementation of the mandatory version entry point @@ -121,6 +124,8 @@ MYSQL_MONITOR *handle; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; + handle->id = MONITOR_DEFAULT_ID; + handle->interval = MONITOR_INTERVAL; spinlock_init(&handle->lock); } handle->tid = (THREAD)thread_start(monitorMain, handle); @@ -434,6 +439,19 @@ long master_id; ptr = ptr->next; } - thread_millisleep(MONITOR_INTERVAL); + thread_millisleep(handle->interval); } } + +/** + * Set the monitor sampling interval. + * + * @param arg The handle allocated by startMonitor + * @param interval The interval to set in monitor struct, in milliseconds + */ +static void +setInterval(void *arg, unsigned long interval) +{ +MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; + memcpy(&handle->interval, &interval, sizeof(unsigned long)); +} diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index ddf1f7cbc..2be29c82d 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -30,6 +30,8 @@ * diagnostic interface * 20/05/14 Massimiliano Pinto Addition of support for MariadDB multimaster replication setup. * New server field version_string is updated. + * 28/05/14 Massimiliano Pinto Added set Id and configuration options (setInverval) + * Parameters are now printed in diagnostics * * @endverbatim */ @@ -51,7 +53,7 @@ extern int lm_enabled_logfiles_bitmask; static void monitorMain(void *); -static char *version_str = "V1.1.0"; +static char *version_str = "V1.1.1"; static void *startMonitor(void *); static void stopMonitor(void *); @@ -59,8 +61,10 @@ static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); static void defaultUser(void *, char *, char *); static void diagnostics(DCB *, void *); +static void setInterval(void *, unsigned long); +static void defaultId(void *, unsigned long); -static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser, diagnostics }; +static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser, diagnostics, setInterval, defaultId }; /** * Implementation of the mandatory version entry point @@ -126,6 +130,8 @@ MYSQL_MONITOR *handle; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; + handle->id = MONITOR_DEFAULT_ID; + handle->interval = MONITOR_INTERVAL; spinlock_init(&handle->lock); } handle->tid = (THREAD)thread_start(monitorMain, handle); @@ -261,7 +267,11 @@ char *sep; dcb_printf(dcb, "\tMonitor stopped\n"); break; } + + dcb_printf(dcb,"\tSampling interval:\t\t%lu milliseconds\n", handle->interval); + dcb_printf(dcb,"\tMaxScale MonitorId:\t\t%lu\n", handle->id); dcb_printf(dcb, "\tMonitored servers: "); + db = handle->databases; sep = ""; while (db) @@ -466,6 +476,32 @@ MONITOR_SERVERS *ptr; monitorDatabase(ptr, handle->defaultUser, handle->defaultPasswd); ptr = ptr->next; } - thread_millisleep(10000); + thread_millisleep(handle->interval); } } + +/** + * Set the default id to use in the monitor. + * + * @param arg The handle allocated by startMonitor + * @param id The id to set in monitor struct + */ +static void +defaultId(void *arg, unsigned long id) +{ +MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; + memcpy(&handle->id, &id, sizeof(unsigned long)); +} + +/** + * Set the monitor sampling interval. + * + * @param arg The handle allocated by startMonitor + * @param interval The interval to set in monitor struct, in milliseconds + */ +static void +setInterval(void *arg, unsigned long interval) +{ +MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; + memcpy(&handle->interval, &interval, sizeof(unsigned long)); +} diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index a2c2e364c..78b929393 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -30,6 +30,7 @@ * Date Who Description * 08/07/13 Mark Riddoch Initial implementation * 26/05/14 Massimiliano Pinto Default values for MONITOR_INTERVAL + * 28/05/14 Massimiliano Pinto Addition of new fields in MYSQL_MONITOR struct * * @endverbatim */ @@ -55,6 +56,8 @@ typedef struct { int status; /**< Monitor status */ char *defaultUser; /**< Default username for monitoring */ char *defaultPasswd; /**< Default password for monitoring */ + unsigned long interval; /**< Monitor sampling interval */ + unsigned long id; /**< Monitor ID */ MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ } MYSQL_MONITOR; @@ -63,5 +66,6 @@ typedef struct { #define MONITOR_STOPPED 3 #define MONITOR_INTERVAL 10000 // in milliseconds +#define MONITOR_DEFAULT_ID 1UL // unsigned long value #endif