Enable online modification of monitors

The monitor parameters can now be changed via maxadmin. These changes are
not persisted to disk yet.
This commit is contained in:
Markus Makela 2016-11-10 10:22:45 +02:00
parent 35d2959395
commit 4b82f83637
3 changed files with 95 additions and 7 deletions

View File

@ -137,6 +137,9 @@ typedef enum
#define MONITOR_INTERVAL 10000 // in milliseconds
#define MONITOR_DEFAULT_ID 1UL // unsigned long value
#define MAX_MONITOR_USER_LEN 512
#define MAX_MONITOR_PASSWORD_LEN 512
/*
* Create declarations of the enum for monitor events and also the array of
* structs containing the matching names. The data is taken from def_monitor_event.h
@ -177,8 +180,8 @@ typedef struct monitor_servers
struct monitor
{
char *name; /**< The name of the monitor module */
char *user; /*< Monitor username */
char *password; /*< Monitor password */
char user[MAX_MONITOR_USER_LEN]; /*< Monitor username */
char password[MAX_MONITOR_PASSWORD_LEN]; /*< Monitor password */
SPINLOCK lock;
CONFIG_PARAMETER* parameters; /*< configuration parameters */
MONITOR_SERVERS* databases; /*< List of databases the monitor monitors */

View File

@ -93,9 +93,8 @@ monitor_alloc(char *name, char *module)
mon->name = name;
mon->handle = NULL;
mon->databases = NULL;
mon->password = NULL;
mon->user = NULL;
mon->password = NULL;
*mon->password = '\0';
*mon->user = '\0';
mon->read_timeout = DEFAULT_READ_TIMEOUT;
mon->write_timeout = DEFAULT_WRITE_TIMEOUT;
mon->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
@ -377,8 +376,8 @@ void monitorRemoveServer(MONITOR *mon, SERVER *server)
void
monitorAddUser(MONITOR *mon, char *user, char *passwd)
{
mon->user = MXS_STRDUP_A(user);
mon->password = MXS_STRDUP_A(passwd);
snprintf(mon->user, sizeof(mon->user), "%s", user);
snprintf(mon->password, sizeof(mon->password), "%s", passwd);
}
/**

View File

@ -1098,6 +1098,83 @@ static void alterServer(DCB *dcb, SERVER *server, char *key, char *value)
}
}
/**
* @brief Convert a string value to a positive integer
*
* If the value is not a positive integer, an error is printed to @c dcb.
*
* @param dcb Client DCB
* @param value String value
* @return 0 on error, otherwise a positive integer
*/
static long get_positive_int(DCB *dcb, const char *value)
{
char *endptr;
long ival = strtol(value, &endptr, 10);
if (*endptr == '\0' && ival > 0)
{
return ival;
}
dcb_printf(dcb, "Invalid value: %s", value);
return 0;
}
static void alterMonitor(DCB *dcb, MONITOR *monitor, char *key, char *value)
{
bool unknown = false;
if (strcmp(key, "user") == 0)
{
monitorAddUser(monitor, value, monitor->password);
}
else if (strcmp(key, "password") == 0)
{
monitorAddUser(monitor, monitor->user, value);
}
else if (strcmp(key, "monitor_interval") == 0)
{
long ival = get_positive_int(dcb, value);
if (ival)
{
monitorSetInterval(monitor, ival);
}
}
else if (strcmp(key, "backend_connect_timeout") == 0)
{
long ival = get_positive_int(dcb, value);
if (ival)
{
monitorSetNetworkTimeout(monitor, MONITOR_CONNECT_TIMEOUT, ival);
}
}
else if (strcmp(key, "backend_write_timeout") == 0)
{
long ival = get_positive_int(dcb, value);
if (ival)
{
monitorSetNetworkTimeout(monitor, MONITOR_READ_TIMEOUT, ival);
}
}
else if (strcmp(key, "backend_read_timeout") == 0)
{
long ival = get_positive_int(dcb, value);
if (ival)
{
monitorSetNetworkTimeout(monitor, MONITOR_WRITE_TIMEOUT, ival);
}
}
else
{
unknown = true;
}
if (unknown)
{
dcb_printf(dcb, "Unknown parameter '%s'", key);
}
}
struct subcommand alteroptions[] =
{
{
@ -1108,6 +1185,15 @@ struct subcommand alteroptions[] =
"for KEY are: 'address', 'port', 'monuser', 'monpw'",
{ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING}
},
{
"monitor", 3, 3, alterMonitor,
"Alter monitor parameters",
"Usage: alter monitor NAME KEY VALUE\n"
"This will alter an existing parameter of a monitor. The accepted values\n"
"for KEY are: 'user', 'password', 'monitor_interval',\n"
"'backend_connect_timeout', 'backend_write_timeout', 'backend_read_timeout'",
{ARG_TYPE_MONITOR, ARG_TYPE_STRING, ARG_TYPE_STRING}
},
{
EMPTY_OPTION
}