MXS-1220: Implement JSON diagnostics entry point in monitors

All monitors now implement the JSON version of the diagnostics function.
This commit is contained in:
Markus Mäkelä 2017-04-18 06:18:02 +03:00 committed by Markus Mäkelä
parent 9d108a58de
commit 5e679aa167
5 changed files with 91 additions and 104 deletions

View File

@ -245,9 +245,9 @@ stopMonitor(MXS_MONITOR *mon)
* @param dcb DCB to send output
* @param mon The monitor
*/
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
static json_t* diagnostics(const MXS_MONITOR *mon)
{
return NULL;
}
/**

View File

@ -49,7 +49,7 @@ static bool warn_erange_on_local_index = true;
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params);
static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *get_candidate_master(MXS_MONITOR*);
static MXS_MONITOR_SERVERS *set_cluster_master(MXS_MONITOR_SERVERS *, MXS_MONITOR_SERVERS *, int);
static void disableMasterFailback(void *, int);
@ -218,28 +218,31 @@ stopMonitor(MXS_MONITOR *mon)
/**
* Diagnostic interface
*
* @param dcb DCB to send output
* @param arg The monitor handle
*/
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
static json_t* diagnostics(const MXS_MONITOR *mon)
{
const GALERA_MONITOR *handle = (const GALERA_MONITOR *) mon->handle;
json_t* rval = json_object();
const GALERA_MONITOR *handle = (const GALERA_MONITOR *)mon->handle;
json_object_set_new(rval, "disable_master_failback", json_boolean(handle->disableMasterFailback));
json_object_set_new(rval, "disable_master_role_setting", json_boolean(handle->disableMasterRoleSetting));
json_object_set_new(rval, "root_node_as_master", json_boolean(handle->root_node_as_master));
json_object_set_new(rval, "use_priority", json_boolean(handle->use_priority));
json_object_set_new(rval, "set_donor_nodes", json_boolean(handle->set_donor_nodes));
if (handle->script)
{
json_object_set_new(rval, "script", json_string(handle->script));
}
dcb_printf(dcb, "Master Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
dcb_printf(dcb, "Available when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
dcb_printf(dcb, "Master Role Setting Disabled:\t%s\n",
handle->disableMasterRoleSetting ? "on" : "off");
dcb_printf(dcb, "Set wsrep_sst_donor node list:\t%s\n", (handle->set_donor_nodes == 1) ? "on" : "off");
if (handle->cluster_info.c_uuid)
{
dcb_printf(dcb, "Galera Cluster UUID:\t%s\n", handle->cluster_info.c_uuid);
dcb_printf(dcb, "Galera Cluster size:\t%d\n", handle->cluster_info.c_size);
}
else
{
dcb_printf(dcb, "Galera Cluster NOT set:\tno member nodes\n");
json_object_set_new(rval, "cluster_uuid", json_string(handle->cluster_info.c_uuid));
json_object_set_new(rval, "cluster_size", json_integer(handle->cluster_info.c_size));
}
return rval;
}
/**
@ -304,10 +307,10 @@ monitorDatabase(MXS_MONITOR *mon, MXS_MONITOR_SERVERS *database)
/* Check if the the Galera FSM shows this node is joined to the cluster */
char *cluster_member = "SHOW STATUS WHERE Variable_name IN"
" ('wsrep_cluster_state_uuid',"
" 'wsrep_cluster_size',"
" 'wsrep_local_index',"
" 'wsrep_local_state')";
" ('wsrep_cluster_state_uuid',"
" 'wsrep_cluster_size',"
" 'wsrep_local_index',"
" 'wsrep_local_state')";
if (mysql_query(database->con, cluster_member) == 0
&& (result = mysql_store_result(database->con)) != NULL)
@ -399,7 +402,7 @@ monitorDatabase(MXS_MONITOR *mon, MXS_MONITOR_SERVERS *database)
if (row[1] == NULL || !strlen(row[1]))
{
MXS_DEBUG("Node %s is not running Galera Cluster",
database->server->unique_name);
database->server->unique_name);
info.cluster_uuid = NULL;
info.joined = 0;
}
@ -431,8 +434,8 @@ monitorDatabase(MXS_MONITOR *mon, MXS_MONITOR_SERVERS *database)
{
if (hashtable_add(table, database->server->unique_name, &info))
{
MXS_DEBUG("Added %s to galera_nodes_info",
database->server->unique_name);
MXS_DEBUG("Added %s to galera_nodes_info",
database->server->unique_name);
}
/* Free the info.cluster_uuid as it's been added to the table */
MXS_FREE(info.cluster_uuid);
@ -1311,13 +1314,13 @@ static bool detect_cluster_size(const GALERA_MONITOR *handle,
}
else
{
if (!ret && c_uuid)
{
/* This error is being logged at every monitor cycle */
MXS_ERROR("Galera cluster cannot be set with %d members of %d:"
" not enough nodes (%d at least)",
candidate_size, n_nodes, min_cluster_size);
}
if (!ret && c_uuid)
{
/* This error is being logged at every monitor cycle */
MXS_ERROR("Galera cluster cannot be set with %d members of %d:"
" not enough nodes (%d at least)",
candidate_size, n_nodes, min_cluster_size);
}
}
}

View File

@ -13,16 +13,6 @@
/**
* @file mm_mon.c - A Multi-Master Multi Muster cluster monitor
*
* @verbatim
* Revision History
*
* Date Who Description
* 08/09/14 Massimiliano Pinto Initial implementation
* 08/05/15 Markus Makela Addition of launchable scripts
* 17/10/15 Martin Brampton Change DCB callback to hangup
*
* @endverbatim
*/
#define MXS_MODULE_NAME "mmmon"
@ -49,7 +39,7 @@ MXS_MODULE info =
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static void detectStaleMaster(void *, int);
static MXS_MONITOR_SERVERS *get_current_master(MXS_MONITOR *);
static bool isMySQLEvent(mxs_monitor_event_t event);
@ -174,16 +164,17 @@ stopMonitor(MXS_MONITOR *mon)
}
/**
* Daignostic interface
* Diagnostic interface
*
* @param dcb DCB to print diagnostics
* @param arg The monitor handle
*/
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
static json_t* diagnostics(const MXS_MONITOR *mon)
{
const MM_MONITOR *handle = (const MM_MONITOR *) mon->handle;
const MM_MONITOR *handle = (const MM_MONITOR *)mon->handle;
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
json_t* rval = json_object();
json_object_set_new(rval, "detect_stale_master", json_boolean(handle->detectStaleMaster));
return rval;
}
/**

View File

@ -13,36 +13,6 @@
/**
* @file mysql_mon.c - A MySQL replication cluster monitor
*
* @verbatim
* Revision History
*
* Date Who Description
* 08/07/13 Mark Riddoch Initial implementation
* 11/07/13 Mark Riddoch Addition of code to check replication status
* 25/07/13 Mark Riddoch Addition of decrypt for passwords and 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
* 03/06/14 Mark Ridoch Add support for maintenance mode
* 17/06/14 Massimiliano Pinto Addition of getServerByNodeId routine and first implementation for
* depth of replication for nodes.
* 23/06/14 Massimiliano Pinto Added replication consistency after replication tree computation
* 27/06/14 Massimiliano Pinto Added replication pending status in monitored server, storing there
* the status to update in server status field before
* starting the replication consistency check.
* This will also give routers a consistent "status" of all servers
* 28/08/14 Massimiliano Pinto Added detectStaleMaster feature: previous detected master will be used again, even if the replication is stopped.
* This means both IO and SQL threads are not working on slaves.
* This option is not enabled by default.
* 10/11/14 Massimiliano Pinto Addition of setNetworkTimeout for connect, read, write
* 18/11/14 Massimiliano Pinto One server only in configuration becomes master. servers=server1 must
* be present in mysql_mon and in router sections as well.
* 08/05/15 Markus Makela Added launchable scripts
* 17/10/15 Martin Brampton Change DCB callback to hangup
*
* @endverbatim
*/
#define MXS_MODULE_NAME "mysqlmon"
@ -78,7 +48,7 @@ static void monitorMain(void *);
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER*);
static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *getServerByNodeId(MXS_MONITOR_SERVERS *, long);
static MXS_MONITOR_SERVERS *getSlaveOfNodeId(MXS_MONITOR_SERVERS *, long);
static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *, int);
@ -341,40 +311,63 @@ stopMonitor(MXS_MONITOR *mon)
}
/**
* Daignostic interface
* Diagnostic interface
*
* @param dcb DCB to print diagnostics
* @param arg The monitor handle
*/
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
static json_t* diagnostics(const MXS_MONITOR *mon)
{
json_t* rval = json_object();
const MYSQL_MONITOR *handle = (const MYSQL_MONITOR *)mon->handle;
json_object_set_new(rval, "monitor_id", json_integer(handle->id));
json_object_set_new(rval, "detect_stale_master", json_boolean(handle->detectStaleMaster));
json_object_set_new(rval, "detect_stale_slave", json_boolean(handle->detectStaleSlave));
json_object_set_new(rval, "detect_replication_lag", json_boolean(handle->replicationHeartbeat));
json_object_set_new(rval, "multimaster", json_boolean(handle->multimaster));
json_object_set_new(rval, "detect_standalone_master", json_boolean(handle->detect_standalone_master));
json_object_set_new(rval, "failcount", json_integer(handle->failcount));
json_object_set_new(rval, "allow_cluster_recovery", json_boolean(handle->allow_cluster_recovery));
json_object_set_new(rval, "mysql51_replication", json_boolean(handle->mysql51_replication));
json_object_set_new(rval, "journal_max_age", json_integer(handle->journal_max_age));
dcb_printf(dcb, "MaxScale MonitorId:\t%lu\n", handle->id);
dcb_printf(dcb, "Replication lag:\t%s\n", (handle->replicationHeartbeat == 1) ? "enabled" : "disabled");
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
dcb_printf(dcb, "Server information\n\n");
for (MXS_MONITOR_SERVERS *db = mon->databases; db; db = db->next)
if (handle->script)
{
MYSQL_SERVER_INFO *serv_info = hashtable_fetch(handle->server_info, db->server->unique_name);
dcb_printf(dcb, "Server: %s\n", db->server->unique_name);
dcb_printf(dcb, "Server ID: %d\n", serv_info->server_id);
dcb_printf(dcb, "Read only: %s\n", serv_info->read_only ? "ON" : "OFF");
dcb_printf(dcb, "Slave configured: %s\n", serv_info->slave_configured ? "YES" : "NO");
dcb_printf(dcb, "Slave IO running: %s\n", serv_info->slave_io ? "YES" : "NO");
dcb_printf(dcb, "Slave SQL running: %s\n", serv_info->slave_sql ? "YES" : "NO");
dcb_printf(dcb, "Master ID: %d\n", serv_info->master_id);
dcb_printf(dcb, "Master binlog file: %s\n", serv_info->binlog_name);
dcb_printf(dcb, "Master binlog position: %lu\n", serv_info->binlog_pos);
json_object_set_new(rval, "script", json_string(handle->script));
}
if (handle->multimaster)
if (mon->databases)
{
json_t* arr = json_array();
for (MXS_MONITOR_SERVERS *db = mon->databases; db; db = db->next)
{
dcb_printf(dcb, "Master group: %d\n", serv_info->group);
json_t* srv = json_object();
MYSQL_SERVER_INFO *serv_info = hashtable_fetch(handle->server_info, db->server->unique_name);
json_object_set_new(srv, "name", json_string(db->server->unique_name));
json_object_set_new(srv, "server_id", json_integer(serv_info->server_id));
json_object_set_new(srv, "master_id", json_integer(serv_info->master_id));
json_object_set_new(srv, "read_only", json_boolean(serv_info->read_only));
json_object_set_new(srv, "slave_configured", json_boolean(serv_info->slave_configured));
json_object_set_new(srv, "slave_io_running", json_boolean(serv_info->slave_io));
json_object_set_new(srv, "slave_sql_running", json_boolean(serv_info->slave_sql));
json_object_set_new(srv, "master_binlog_file", json_string(serv_info->binlog_name));
json_object_set_new(srv, "master_binlog_position", json_integer(serv_info->binlog_pos));
if (handle->multimaster)
{
json_object_set_new(srv, "master_group", json_integer(serv_info->group));
}
json_array_append(arr, srv);
}
dcb_printf(dcb, "\n");
json_object_set_new(rval, "server_info", arr);
}
return rval;
}
enum mysql_server_version

View File

@ -41,7 +41,7 @@ static void monitorMain(void *);
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params);
static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
bool isNdbEvent(mxs_monitor_event_t event);
@ -170,9 +170,9 @@ stopMonitor(MXS_MONITOR *mon)
* @param dcb DCB to send output
* @param arg The monitor handle
*/
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
static json_t* diagnostics(const MXS_MONITOR *mon)
{
return NULL;
}
/**