
When the servers of a service are defined by a monitor, then at startup all servers of the monitor should be added to relevant services. Likewise, when a server is added to or removed from a monitor at runtime, those changes should affect services as well. However, whether that should happen or not depends upon the monitor. In the case of the Clustrix monitor this should not happen as it adds and removes servers depending on the runtime state of the Clustrix cluster.
170 lines
5.1 KiB
C++
170 lines
5.1 KiB
C++
/*
|
|
* Copyright (c) 2018 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
*
|
|
* Change Date: 2022-01-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
#pragma once
|
|
|
|
/**
|
|
* Internal header for the monitor
|
|
*/
|
|
|
|
#include <maxscale/monitor.hh>
|
|
#include <maxscale/resultset.hh>
|
|
#include "externcmd.hh"
|
|
|
|
#define MON_ARG_MAX 8192
|
|
|
|
#define DEFAULT_CONNECT_TIMEOUT 3
|
|
#define DEFAULT_READ_TIMEOUT 3
|
|
#define DEFAULT_WRITE_TIMEOUT 3
|
|
#define DEFAULT_CONNECTION_ATTEMPTS 1
|
|
|
|
#define DEFAULT_MONITOR_INTERVAL 2000 // in milliseconds
|
|
|
|
/** Default maximum journal age in seconds */
|
|
#define DEFAULT_JOURNAL_MAX_AGE 28800
|
|
|
|
/** Default script execution timeout in seconds */
|
|
#define DEFAULT_SCRIPT_TIMEOUT 90
|
|
|
|
/**
|
|
* Monitor network timeout types
|
|
*/
|
|
typedef enum
|
|
{
|
|
MONITOR_CONNECT_TIMEOUT = 0,
|
|
MONITOR_READ_TIMEOUT = 1,
|
|
MONITOR_WRITE_TIMEOUT = 2,
|
|
MONITOR_CONNECT_ATTEMPTS = 3
|
|
} monitor_timeouts_t;
|
|
|
|
/* Is not really an event as the other values, but is a valid config setting and also the default.
|
|
* Bitmask value matches all events. */
|
|
static const MXS_ENUM_VALUE mxs_monitor_event_default_enum = {"all", ~0ULL};
|
|
static const MXS_ENUM_VALUE mxs_monitor_event_enum_values[] =
|
|
{
|
|
mxs_monitor_event_default_enum,
|
|
{"master_down", MASTER_DOWN_EVENT },
|
|
{"master_up", MASTER_UP_EVENT },
|
|
{"slave_down", SLAVE_DOWN_EVENT },
|
|
{"slave_up", SLAVE_UP_EVENT },
|
|
{"server_down", SERVER_DOWN_EVENT },
|
|
{"server_up", SERVER_UP_EVENT },
|
|
{"synced_down", SYNCED_DOWN_EVENT },
|
|
{"synced_up", SYNCED_UP_EVENT },
|
|
{"donor_down", DONOR_DOWN_EVENT },
|
|
{"donor_up", DONOR_UP_EVENT },
|
|
{"ndb_down", NDB_DOWN_EVENT },
|
|
{"ndb_up", NDB_UP_EVENT },
|
|
{"lost_master", LOST_MASTER_EVENT },
|
|
{"lost_slave", LOST_SLAVE_EVENT },
|
|
{"lost_synced", LOST_SYNCED_EVENT },
|
|
{"lost_donor", LOST_DONOR_EVENT },
|
|
{"lost_ndb", LOST_NDB_EVENT },
|
|
{"new_master", NEW_MASTER_EVENT },
|
|
{"new_slave", NEW_SLAVE_EVENT },
|
|
{"new_synced", NEW_SYNCED_EVENT },
|
|
{"new_donor", NEW_DONOR_EVENT },
|
|
{"new_ndb", NEW_NDB_EVENT },
|
|
{NULL}
|
|
};
|
|
|
|
std::unique_ptr<ResultSet> monitor_get_list();
|
|
|
|
/**
|
|
* This class contains internal monitor management functions that should not be exposed in the public
|
|
* monitor class. It's a friend of MXS_MONITOR.
|
|
*/
|
|
class MonitorManager
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* Creates a new monitor. Loads the module, calls constructor and configure, and adds monitor to the
|
|
* global list.
|
|
*
|
|
* @param name The configuration name of the monitor
|
|
* @param module The module name to load
|
|
* @return The newly created monitor, or NULL on error
|
|
*/
|
|
static Monitor* create_monitor(const std::string& name, const std::string& module,
|
|
MXS_CONFIG_PARAMETER* params);
|
|
|
|
/**
|
|
* @brief Destroys all monitors. At this point all monitors should
|
|
* have been stopped.
|
|
*
|
|
* @attn Must only be called in single-thread context at system shutdown.
|
|
*/
|
|
static void destroy_all_monitors();
|
|
|
|
static void monitor_start(Monitor*, const MXS_CONFIG_PARAMETER*);
|
|
|
|
/**
|
|
* @brief Populate services with the servers of the monitors.
|
|
*/
|
|
static void populate_services();
|
|
|
|
static bool add_server(Monitor* mon, SERVER* server)
|
|
{
|
|
return Monitor::add_server(mon, server);
|
|
}
|
|
|
|
static void remove_server(Monitor* mon, SERVER* server)
|
|
{
|
|
Monitor::remove_server(mon, server);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
void monitor_stop(Monitor*);
|
|
|
|
/**
|
|
* @brief Mark monitor as deactivated
|
|
*
|
|
* A deactivated monitor appears not to exist, as if it had been
|
|
* destroyed.
|
|
*
|
|
* @param monitor
|
|
*/
|
|
void monitor_deactivate(Monitor* monitor);
|
|
|
|
void monitor_stop_all();
|
|
void monitor_start_all();
|
|
|
|
Monitor* monitor_find(const char*);
|
|
Monitor* monitor_repurpose_destroyed(const char* name, const char* module);
|
|
|
|
void monitor_show(DCB*, Monitor*);
|
|
void monitor_show_all(DCB*);
|
|
|
|
void monitor_list(DCB*);
|
|
|
|
void monitor_set_journal_max_age(Monitor* mon, time_t value);
|
|
|
|
/**
|
|
* @brief Serialize a monitor to a file
|
|
*
|
|
* This converts the static configuration of the monitor into an INI format file.
|
|
*
|
|
* @param monitor Monitor to serialize
|
|
* @return True if serialization was successful
|
|
*/
|
|
bool monitor_serialize(const Monitor* monitor);
|
|
|
|
/**
|
|
* Check if a server is being monitored and return the monitor.
|
|
* @param server Server that is queried
|
|
* @return The monitor watching this server, or NULL if not monitored
|
|
*/
|
|
Monitor* monitor_server_in_use(const SERVER* server);
|