Monitor API 2.0.0 implemented.

This commit is contained in:
Markus Makela
2015-03-11 15:18:55 +02:00
parent 9209c812ba
commit 63d83cd85d
15 changed files with 66 additions and 133 deletions

View File

@ -118,6 +118,7 @@ include_directories(utils)
include_directories(log_manager) include_directories(log_manager)
include_directories(query_classifier) include_directories(query_classifier)
include_directories(server/include) include_directories(server/include)
include_directories(server/include/maxscale)
include_directories(server/inih) include_directories(server/inih)
include_directories(server/modules/include) include_directories(server/modules/include)
include_directories(${CMAKE_BINARY_DIR}/server/include) include_directories(${CMAKE_BINARY_DIR}/server/include)

View File

@ -51,7 +51,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <ini.h> #include <ini.h>
#include <config.h> #include <maxconfig.h>
#include <service.h> #include <service.h>
#include <server.h> #include <server.h>
#include <users.h> #include <users.h>
@ -895,26 +895,12 @@ int error_count = 0;
gateway.id = getpid(); gateway.id = getpid();
} }
monitorStart(obj->element,obj->parameters) monitorStart(obj->element,obj->parameters);
/* add the maxscale-id to monitor data */
monitorSetId(obj->element, gateway.id);
/* set monitor interval */ /* set monitor interval */
if (interval > 0) if (interval > 0)
monitorSetInterval(obj->element, interval); monitorSetInterval(obj->element, interval);
/* set replication heartbeat */
if(replication_heartbeat == 1)
monitorSetReplicationHeartbeat(obj->element, replication_heartbeat);
/* detect stale master */
if(detect_stale_master == 1)
monitorDetectStaleMaster(obj->element, detect_stale_master);
/* disable master failback */
if(disable_master_failback == 1)
monitorDisableMasterFailback(obj->element, disable_master_failback);
/* set timeouts */ /* set timeouts */
if (connect_timeout > 0) if (connect_timeout > 0)
monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, connect_timeout); monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, connect_timeout);

View File

@ -53,7 +53,7 @@
#include <dcb.h> #include <dcb.h>
#include <session.h> #include <session.h>
#include <modules.h> #include <modules.h>
#include <config.h> #include <maxconfig.h>
#include <poll.h> #include <poll.h>
#include <housekeeper.h> #include <housekeeper.h>
#include <service.h> #include <service.h>

View File

@ -78,8 +78,10 @@ MONITOR *mon;
free(mon); free(mon);
return NULL; return NULL;
} }
/*
mon->handle = (*mon->module->startMonitor)(NULL); mon->handle = (*mon->module->startMonitor)(NULL);
mon->state = MONITOR_STATE_RUNNING; mon->state = MONITOR_STATE_RUNNING;
*/
spinlock_acquire(&monLock); spinlock_acquire(&monLock);
mon->next = allMonitors; mon->next = allMonitors;
@ -125,9 +127,9 @@ MONITOR *ptr;
* @param monitor The Monitor that should be started * @param monitor The Monitor that should be started
*/ */
void void
monitorStart(MONITOR *monitor) monitorStart(MONITOR *monitor, void* params)
{ {
monitor->handle = (*monitor->module->startMonitor)(monitor->handle); monitor->handle = (*monitor->module->startMonitor)(monitor->handle,params);
monitor->state = MONITOR_STATE_RUNNING; monitor->state = MONITOR_STATE_RUNNING;
} }
@ -279,22 +281,6 @@ MONITOR *ptr;
return ptr; 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. * Set the monitor sampling interval.
* *
@ -310,48 +296,6 @@ monitorSetInterval (MONITOR *mon, unsigned long interval)
} }
} }
/**
* Enable Replication Heartbeat support in monitor.
*
* @param mon The monitor instance
* @param enable The enabling value is 1, 0 turns it off
*/
void
monitorSetReplicationHeartbeat(MONITOR *mon, int enable)
{
if (mon->module->replicationHeartbeat != NULL) {
mon->module->replicationHeartbeat(mon->handle, enable);
}
}
/**
* Enable Stale Master assignement.
*
* @param mon The monitor instance
* @param enable The enabling value is 1, 0 turns it off
*/
void
monitorDetectStaleMaster(MONITOR *mon, int enable)
{
if (mon->module->detectStaleMaster != NULL) {
mon->module->detectStaleMaster(mon->handle, enable);
}
}
/**
* Disable Master Failback
*
* @param mon The monitor instance
* @param disable The value 1 disable the failback, 0 keeps it
*/
void
monitorDisableMasterFailback(MONITOR *mon, int disable)
{
if (mon->module->disableMasterFailback != NULL) {
mon->module->disableMasterFailback(mon->handle, disable);
}
}
/** /**
* Set Monitor timeouts for connect/read/write * Set Monitor timeouts for connect/read/write
* *

View File

@ -28,7 +28,7 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
#include <gw.h> #include <gw.h>
#include <config.h> #include <maxconfig.h>
#include <housekeeper.h> #include <housekeeper.h>
#include <config.h> #include <config.h>
#include <mysql.h> #include <mysql.h>

View File

@ -33,7 +33,7 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include "../../include/hashtable.h" #include <hashtable.h>
static void static void
read_lock(HASHTABLE *table) read_lock(HASHTABLE *table)

View File

@ -73,22 +73,15 @@ typedef struct {
void (*unregisterServer)(void *, SERVER *); void (*unregisterServer)(void *, SERVER *);
void (*defaultUser)(void *, char *, char *); void (*defaultUser)(void *, char *, char *);
void (*diagnostics)(DCB *, void *); void (*diagnostics)(DCB *, void *);
void (*setInterval)(void *, size_t); void (*setInterval)(void *, size_t);
void (*setNetworkTimeout)(void *, int, int); void (*setNetworkTimeout)(void *, int, int);
void (*defaultId)(void *, unsigned long);
void (*replicationHeartbeat)(void *, int);
void (*detectStaleMaster)(void *, int);
void (*disableMasterFailback)(void *, int);
} MONITOR_OBJECT; } MONITOR_OBJECT;
/** /**
* The monitor API version number. Any change to the monitor module API * The monitor API version number. Any change to the monitor module API
* must change these versions usign the rules defined in modinfo.h * must change these versions usign the rules defined in modinfo.h
*/ */
#define MONITOR_VERSION {1, 0, 0} #define MONITOR_VERSION {2, 0, 0}
/** Monitor's poll frequency */ /** Monitor's poll frequency */
#define MON_BASE_INTERVAL_MS 100 #define MON_BASE_INTERVAL_MS 100
@ -137,7 +130,7 @@ extern MONITOR *monitor_find(char *);
extern void monitorAddServer(MONITOR *, SERVER *); extern void monitorAddServer(MONITOR *, SERVER *);
extern void monitorAddUser(MONITOR *, char *, char *); extern void monitorAddUser(MONITOR *, char *, char *);
extern void monitorStop(MONITOR *); extern void monitorStop(MONITOR *);
extern void monitorStart(MONITOR *); extern void monitorStart(MONITOR *, void*);
extern void monitorStopAll(); extern void monitorStopAll();
extern void monitorShowAll(DCB *); extern void monitorShowAll(DCB *);
extern void monitorShow(DCB *, MONITOR *); extern void monitorShow(DCB *, MONITOR *);

View File

@ -25,7 +25,7 @@
#include <filter.h> #include <filter.h>
#include <hashtable.h> #include <hashtable.h>
#include <resultset.h> #include <resultset.h>
#include "config.h" #include <maxconfig.h>
/** /**
* @file service.h * @file service.h

View File

@ -49,6 +49,7 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
#include <modinfo.h> #include <modinfo.h>
#include <maxconfig.h>
/** Defined in log_manager.cc */ /** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask; extern int lm_enabled_logfiles_bitmask;
@ -66,7 +67,7 @@ MODULE_INFO info = {
"A Galera cluster monitor" "A Galera cluster monitor"
}; };
static void *startMonitor(void *); static void *startMonitor(void *,void*);
static void stopMonitor(void *); static void stopMonitor(void *);
static void registerServer(void *, SERVER *); static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
@ -88,11 +89,7 @@ static MONITOR_OBJECT MyObject = {
defaultUsers, defaultUsers,
diagnostics, diagnostics,
setInterval, setInterval,
setNetworkTimeout, setNetworkTimeout
NULL,
NULL,
NULL,
disableMasterFailback
}; };
/** /**
@ -141,10 +138,10 @@ GetModuleObject()
* @return A handle to use when interacting with the monitor * @return A handle to use when interacting with the monitor
*/ */
static void * static void *
startMonitor(void *arg) startMonitor(void *arg,void* opt)
{ {
MYSQL_MONITOR *handle; MYSQL_MONITOR *handle;
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
if (arg != NULL) if (arg != NULL)
{ {
handle = (MYSQL_MONITOR *)arg; handle = (MYSQL_MONITOR *)arg;
@ -158,7 +155,7 @@ MYSQL_MONITOR *handle;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->defaultPasswd = NULL; handle->defaultPasswd = NULL;
handle->id = MONITOR_DEFAULT_ID; handle->id = config_get_gateway_id();
handle->interval = MONITOR_INTERVAL; handle->interval = MONITOR_INTERVAL;
handle->disableMasterFailback = 0; handle->disableMasterFailback = 0;
handle->master = NULL; handle->master = NULL;
@ -167,6 +164,15 @@ MYSQL_MONITOR *handle;
handle->write_timeout=DEFAULT_WRITE_TIMEOUT; handle->write_timeout=DEFAULT_WRITE_TIMEOUT;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
while(params)
{
if(!strcmp(params->name,"disable_master_failback"))
handle->disableMasterFailback = config_truth_value(params->value);
params = params->next;
}
handle->tid = (THREAD)thread_start(monitorMain, handle); handle->tid = (THREAD)thread_start(monitorMain, handle);
return handle; return handle;
} }

View File

@ -41,7 +41,7 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
#include <modinfo.h> #include <modinfo.h>
#include <maxconfig.h>
/** Defined in log_manager.cc */ /** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask; extern int lm_enabled_logfiles_bitmask;
extern size_t log_ses_count[]; extern size_t log_ses_count[];
@ -58,7 +58,7 @@ MODULE_INFO info = {
"A MySQL Multi Master monitor" "A MySQL Multi Master monitor"
}; };
static void *startMonitor(void *); static void *startMonitor(void *,void*);
static void stopMonitor(void *); static void stopMonitor(void *);
static void registerServer(void *, SERVER *); static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
@ -79,12 +79,7 @@ static MONITOR_OBJECT MyObject = {
unregisterServer, unregisterServer,
defaultUser, defaultUser,
diagnostics, diagnostics,
setInterval, setInterval
NULL,
NULL,
NULL,
detectStaleMaster,
NULL
}; };
/** /**
@ -134,10 +129,10 @@ GetModuleObject()
* @return A handle to use when interacting with the monitor * @return A handle to use when interacting with the monitor
*/ */
static void * static void *
startMonitor(void *arg) startMonitor(void *arg,void* opt)
{ {
MYSQL_MONITOR *handle; MYSQL_MONITOR *handle;
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
if (arg) if (arg)
{ {
handle = arg; /* Must be a restart */ handle = arg; /* Must be a restart */
@ -151,13 +146,21 @@ MYSQL_MONITOR *handle;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->defaultPasswd = NULL; handle->defaultPasswd = NULL;
handle->id = MONITOR_DEFAULT_ID; handle->id = config_get_gateway_id();
handle->interval = MONITOR_INTERVAL; handle->interval = MONITOR_INTERVAL;
handle->replicationHeartbeat = 0; handle->replicationHeartbeat = 0;
handle->detectStaleMaster = 0; handle->detectStaleMaster = 0;
handle->master = NULL; handle->master = NULL;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
while(params)
{
if(!strcmp(params->name,"detect_stale_master"))
handle->detectStaleMaster = config_truth_value(params->value);
params = params->next;
}
handle->tid = (THREAD)thread_start(monitorMain, handle); handle->tid = (THREAD)thread_start(monitorMain, handle);
return handle; return handle;
} }

View File

@ -63,8 +63,7 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
#include <modinfo.h> #include <modinfo.h>
#include <maxconfig.h>
#include "config.h"
/** Defined in log_manager.cc */ /** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask; extern int lm_enabled_logfiles_bitmask;
@ -82,7 +81,7 @@ MODULE_INFO info = {
"A MySQL Master/Slave replication monitor" "A MySQL Master/Slave replication monitor"
}; };
static void *startMonitor(void *); static void *startMonitor(void *,void*);
static void stopMonitor(void *); static void stopMonitor(void *);
static void registerServer(void *, SERVER *); static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
@ -90,8 +89,6 @@ static void defaultUser(void *, char *, char *);
static void diagnostics(DCB *, void *); static void diagnostics(DCB *, void *);
static void setInterval(void *, size_t); static void setInterval(void *, size_t);
static void defaultId(void *, unsigned long); static void defaultId(void *, unsigned long);
static void replicationHeartbeat(void *, int);
static void detectStaleMaster(void *, int);
static void setNetworkTimeout(void *, int, int); static void setNetworkTimeout(void *, int, int);
static bool mon_status_changed(MONITOR_SERVERS* mon_srv); static bool mon_status_changed(MONITOR_SERVERS* mon_srv);
static bool mon_print_fail_status(MONITOR_SERVERS* mon_srv); static bool mon_print_fail_status(MONITOR_SERVERS* mon_srv);
@ -112,11 +109,7 @@ static MONITOR_OBJECT MyObject = {
defaultUser, defaultUser,
diagnostics, diagnostics,
setInterval, setInterval,
setNetworkTimeout, setNetworkTimeout
defaultId,
replicationHeartbeat,
detectStaleMaster,
NULL
}; };
/** /**
@ -183,7 +176,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->defaultPasswd = NULL; handle->defaultPasswd = NULL;
handle->id = MONITOR_DEFAULT_ID; handle->id = config_get_gateway_id();
handle->interval = MONITOR_INTERVAL; handle->interval = MONITOR_INTERVAL;
handle->replicationHeartbeat = 0; handle->replicationHeartbeat = 0;
handle->detectStaleMaster = 0; handle->detectStaleMaster = 0;
@ -193,6 +186,16 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
handle->write_timeout=DEFAULT_WRITE_TIMEOUT; handle->write_timeout=DEFAULT_WRITE_TIMEOUT;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
while(params)
{
if(!strcmp(params->name,"detect_stale_master"))
handle->detectStaleMaster = config_truth_value(params->value);
else if(!strcmp(params->name,"detect_replication_lag"))
handle->replicationHeartbeat = config_truth_value(params->value);
params = params->next;
}
handle->tid = (THREAD)thread_start(monitorMain, handle); handle->tid = (THREAD)thread_start(monitorMain, handle);
return handle; return handle;
} }

View File

@ -42,7 +42,7 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
#include <modinfo.h> #include <modinfo.h>
#include <maxconfig.h>
/** Defined in log_manager.cc */ /** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask; extern int lm_enabled_logfiles_bitmask;
extern size_t log_ses_count[]; extern size_t log_ses_count[];
@ -59,7 +59,7 @@ MODULE_INFO info = {
"A MySQL cluster SQL node monitor" "A MySQL cluster SQL node monitor"
}; };
static void *startMonitor(void *); static void *startMonitor(void *,void*);
static void stopMonitor(void *); static void stopMonitor(void *);
static void registerServer(void *, SERVER *); static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
@ -76,11 +76,7 @@ static MONITOR_OBJECT MyObject = {
defaultUsers, defaultUsers,
diagnostics, diagnostics,
setInterval, setInterval,
setNetworkTimeout, setNetworkTimeout
NULL,
NULL,
NULL,
NULL
}; };
/** /**
@ -129,10 +125,10 @@ GetModuleObject()
* @return A handle to use when interacting with the monitor * @return A handle to use when interacting with the monitor
*/ */
static void * static void *
startMonitor(void *arg) startMonitor(void *arg,void* opt)
{ {
MYSQL_MONITOR *handle; MYSQL_MONITOR *handle;
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
if (arg != NULL) if (arg != NULL)
{ {
handle = (MYSQL_MONITOR *)arg; handle = (MYSQL_MONITOR *)arg;
@ -146,13 +142,14 @@ MYSQL_MONITOR *handle;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->defaultPasswd = NULL; handle->defaultPasswd = NULL;
handle->id = MONITOR_DEFAULT_ID; handle->id = config_get_gateway_id();
handle->interval = MONITOR_INTERVAL; handle->interval = MONITOR_INTERVAL;
handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT; handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT;
handle->read_timeout=DEFAULT_READ_TIMEOUT; handle->read_timeout=DEFAULT_READ_TIMEOUT;
handle->write_timeout=DEFAULT_WRITE_TIMEOUT; handle->write_timeout=DEFAULT_WRITE_TIMEOUT;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
handle->tid = (THREAD)thread_start(monitorMain, handle); handle->tid = (THREAD)thread_start(monitorMain, handle);
return handle; return handle;
} }

View File

@ -63,7 +63,7 @@
#include <poll.h> #include <poll.h>
#include <users.h> #include <users.h>
#include <dbusers.h> #include <dbusers.h>
#include <config.h> #include <maxconfig.h>
#include <telnetd.h> #include <telnetd.h>
#include <adminusers.h> #include <adminusers.h>
#include <monitor.h> #include <monitor.h>
@ -1195,7 +1195,7 @@ shutdown_monitor(DCB *dcb, MONITOR *monitor)
static void static void
restart_monitor(DCB *dcb, MONITOR *monitor) restart_monitor(DCB *dcb, MONITOR *monitor)
{ {
monitorStart(monitor); monitorStart(monitor, NULL);
} }
/** /**

View File

@ -47,7 +47,7 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
#include <resultset.h> #include <resultset.h>
#include <config.h> #include <maxconfig.h>
extern int lm_enabled_logfiles_bitmask; extern int lm_enabled_logfiles_bitmask;
extern size_t log_ses_count[]; extern size_t log_ses_count[];