Added filtering of monitor events.

This commit is contained in:
Markus Makela
2015-05-14 12:05:58 +03:00
parent 1aba13177b
commit b94f494d80
11 changed files with 195 additions and 54 deletions

View File

@ -140,6 +140,8 @@ startMonitor(void *arg, void* opt)
MONITOR* monitor = (MONITOR*)arg;
MYSQL_MONITOR *handle = (MYSQL_MONITOR*)monitor->handle;
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
bool have_events = false;
if (handle)
{
handle->shutdown = 0;
@ -154,6 +156,7 @@ startMonitor(void *arg, void* opt)
handle->detectStaleMaster = 0;
handle->master = NULL;
handle->script = NULL;
memset(handle->events,false,sizeof(handle->events));
spinlock_init(&handle->lock);
}
@ -169,9 +172,18 @@ startMonitor(void *arg, void* opt)
free(handle->script);
handle->script = strdup(params->value);
}
else if(!strcmp(params->name,"events"))
{
mon_parse_event_string(handle->events,sizeof(handle->events),params->value);
have_events = true;
}
params = params->next;
}
/** If no specific events are given, enable them all */
if(!have_events)
{
memset(handle->events,true,sizeof(handle->events));
}
handle->tid = (THREAD)thread_start(monitorMain, monitor);
return handle;
}
@ -677,17 +689,17 @@ int log_no_master = 1;
}
ptr = mon->databases;
monitor_event_t evtype;
while(ptr)
{
/** Execute monitor script if a server state has changed */
if(mon_status_changed(ptr) && mon_get_event_type(ptr) != UNDEFINED_MONITOR_EVENT)
if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT)
{
skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s",
ptr->server->unique_name,
ptr->server->name,ptr->server->port,
mon_get_event_name(ptr));
if(handle->script)
if(handle->script && handle->events[evtype])
{
monitor_launch_script(mon,ptr,handle->script);
}