diff --git a/include/maxscale/modulecmd.hh b/include/maxscale/modulecmd.hh index a0272100b..5787e5709 100644 --- a/include/maxscale/modulecmd.hh +++ b/include/maxscale/modulecmd.hh @@ -96,7 +96,7 @@ struct arg_node SERVER* server; MXS_SESSION* session; DCB* dcb; - Monitor* monitor; + mxs::Monitor* monitor; MXS_FILTER_DEF* filter; } value; }; diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index b048c5e4d..cbffd47f1 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -28,10 +28,15 @@ #include #include +namespace maxscale +{ class Monitor; +} + struct DCB; struct json_t; struct EXTERNCMD; +class MonitorManager; /** * @verbatim @@ -56,9 +61,23 @@ struct MXS_MONITOR_API * @param module Module name of the monitor * @return Monitor object */ - Monitor* (* createInstance)(const std::string& name, const std::string& module); + maxscale::Monitor* (* createInstance)(const std::string& name, const std::string& module); }; +/** + * Monitor configuration parameters names + */ +extern const char CN_BACKEND_CONNECT_ATTEMPTS[]; +extern const char CN_BACKEND_CONNECT_TIMEOUT[]; +extern const char CN_BACKEND_READ_TIMEOUT[]; +extern const char CN_BACKEND_WRITE_TIMEOUT[]; +extern const char CN_DISK_SPACE_CHECK_INTERVAL[]; +extern const char CN_EVENTS[]; +extern const char CN_JOURNAL_MAX_AGE[]; +extern const char CN_MONITOR_INTERVAL[]; +extern const char CN_SCRIPT[]; +extern const char CN_SCRIPT_TIMEOUT[]; + /** * The monitor API version number. Any change to the monitor module API * must change these versions using the rules defined in modinfo.h @@ -129,6 +148,9 @@ enum credentials_approach_t CREDENTIALS_EXCLUDE, }; +namespace maxscale +{ + /** * The linked list of servers that are being monitored by the monitor module. */ @@ -477,7 +499,7 @@ protected: Settings m_settings; private: - friend class MonitorManager; + friend class ::MonitorManager; /** * @brief Add a server to a monitor. @@ -532,23 +554,6 @@ private: int get_data_file_path(char* path) const; }; -/** - * Monitor configuration parameters names - */ -extern const char CN_BACKEND_CONNECT_ATTEMPTS[]; -extern const char CN_BACKEND_CONNECT_TIMEOUT[]; -extern const char CN_BACKEND_READ_TIMEOUT[]; -extern const char CN_BACKEND_WRITE_TIMEOUT[]; -extern const char CN_DISK_SPACE_CHECK_INTERVAL[]; -extern const char CN_EVENTS[]; -extern const char CN_JOURNAL_MAX_AGE[]; -extern const char CN_MONITOR_INTERVAL[]; -extern const char CN_SCRIPT[]; -extern const char CN_SCRIPT_TIMEOUT[]; - -namespace maxscale -{ - /** * An abstract class which helps implement a monitor based on a maxbase::Worker thread. */ diff --git a/server/core/config.cc b/server/core/config.cc index 14c310a07..c5c7f38d6 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -68,6 +68,7 @@ using std::set; using std::string; +using maxscale::Monitor; const char CN_ACCOUNT[] = "account"; const char CN_ADDRESS[] = "address"; diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index fa54339ae..34e62ca28 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -45,6 +45,7 @@ typedef std::set StringSet; typedef std::vector StringVector; using std::tie; +using maxscale::Monitor; static std::mutex crt_lock; diff --git a/server/core/internal/config_runtime.hh b/server/core/internal/config_runtime.hh index 6a3a0e96e..848fee96f 100644 --- a/server/core/internal/config_runtime.hh +++ b/server/core/internal/config_runtime.hh @@ -143,7 +143,7 @@ bool runtime_enable_server_ssl(Server* server, * @param value New value * @return True if @c key was one of the supported parameters */ -bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value); +bool runtime_alter_monitor(mxs::Monitor* monitor, const char* key, const char* value); /** * @brief Alter service parameters @@ -254,7 +254,7 @@ bool runtime_destroy_filter(const SFilterDef& filter); * @param monitor Monitor to destroy * @return True if monitor was destroyed */ -bool runtime_destroy_monitor(Monitor* monitor); +bool runtime_destroy_monitor(mxs::Monitor* monitor); /** * Destroy a service @@ -304,7 +304,7 @@ bool runtime_alter_server_relationships_from_json(Server* server, const char* ty * * @return Created monitor or NULL on error */ -Monitor* runtime_create_monitor_from_json(json_t* json); +mxs::Monitor* runtime_create_monitor_from_json(json_t* json); /** * @brief Create a new filter from JSON @@ -332,7 +332,7 @@ Service* runtime_create_service_from_json(json_t* json); * * @return True if the monitor was successfully modified to represent @c new_json */ -bool runtime_alter_monitor_from_json(Monitor* monitor, json_t* new_json); +bool runtime_alter_monitor_from_json(mxs::Monitor* monitor, json_t* new_json); /** * @brief Alter monitor relationships @@ -342,7 +342,7 @@ bool runtime_alter_monitor_from_json(Monitor* monitor, json_t* new_json); * * @return True if the relationships were successfully modified */ -bool runtime_alter_monitor_relationships_from_json(Monitor* monitor, json_t* json); +bool runtime_alter_monitor_relationships_from_json(mxs::Monitor* monitor, json_t* json); /** * @brief Alter a service using JSON diff --git a/server/core/internal/monitor.hh b/server/core/internal/monitor.hh index 76bc550b7..e6617c59a 100644 --- a/server/core/internal/monitor.hh +++ b/server/core/internal/monitor.hh @@ -69,8 +69,8 @@ public: * @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); + static mxs::Monitor* create_monitor(const std::string& name, const std::string& module, + MXS_CONFIG_PARAMETER* params); /** * Mark monitor as deactivated. A deactivated monitor appears not to exist, as if it had been @@ -79,7 +79,7 @@ public: * * @param monitor Monitor to deactivate */ - static void deactivate_monitor(Monitor* monitor); + static void deactivate_monitor(mxs::Monitor* monitor); /** * @brief Destroys all monitors. At this point all monitors should @@ -89,19 +89,19 @@ public: */ static void destroy_all_monitors(); - static void start_monitor(Monitor* monitor); + static void start_monitor(mxs::Monitor* monitor); /** * Stop a given monitor * * @param monitor The monitor to stop */ - static void stop_monitor(Monitor* monitor); + static void stop_monitor(mxs::Monitor* monitor); static void stop_all_monitors(); static void start_all_monitors(); - static Monitor* find_monitor(const char* name); + static mxs::Monitor* find_monitor(const char* name); /** * @brief Populate services with the servers of the monitors. @@ -130,12 +130,12 @@ public: * @param server Server that is queried * @return The monitor watching this server, or NULL if not monitored */ - static Monitor* server_is_monitored(const SERVER* server); + static mxs::Monitor* server_is_monitored(const SERVER* server); - static Monitor* reactivate_monitor(const char* name, const char* module); + static mxs::Monitor* reactivate_monitor(const char* name, const char* module); static void show_all_monitors(DCB* dcb); - static void monitor_show(DCB* dcb, Monitor* monitor); + static void monitor_show(DCB* dcb, mxs::Monitor* monitor); static void monitor_list(DCB*); @@ -149,7 +149,7 @@ public: * @param monitor Monitor to serialize * @return True if serialization was successful */ - static bool monitor_serialize(const Monitor* monitor); + static bool monitor_serialize(const mxs::Monitor* monitor); /** * @brief Convert monitor to JSON @@ -159,9 +159,9 @@ public: * * @return JSON representation of the monitor */ - static json_t* monitor_to_json(const Monitor* monitor, const char* host); + static json_t* monitor_to_json(const mxs::Monitor* monitor, const char* host); - static bool create_monitor_config(const Monitor* monitor, const char* filename); + static bool create_monitor_config(const mxs::Monitor* monitor, const char* filename); /** * Waits until all running monitors have advanced one tick. diff --git a/server/core/internal/service.hh b/server/core/internal/service.hh index 91246e419..f787532b0 100644 --- a/server/core/internal/service.hh +++ b/server/core/internal/service.hh @@ -21,7 +21,10 @@ #include "filter.hh" +namespace maxscale +{ class Monitor; +} /** * @file service.h - MaxScale internal service functions @@ -106,7 +109,7 @@ public: mutable std::mutex lock; // TODO: Make this private. - Monitor* m_monitor { nullptr }; /**< A possibly associated monitor */ + mxs::Monitor* m_monitor { nullptr }; /**< A possibly associated monitor */ bool uses_cluster() const { @@ -413,7 +416,7 @@ json_t* service_relations_to_filter(const SFilterDef& filter, const char* host); * @param monitor A monitor. * @param server A server. */ -void service_add_server(Monitor* pMonitor, SERVER* pServer); +void service_add_server(mxs::Monitor* pMonitor, SERVER* pServer); /** * @brief Remove server from all services associated with a monitor @@ -421,7 +424,7 @@ void service_add_server(Monitor* pMonitor, SERVER* pServer); * @param monitor A monitor. * @param server A server. */ -void service_remove_server(Monitor* pMonitor, SERVER* pServer); +void service_remove_server(mxs::Monitor* pMonitor, SERVER* pServer); std::unique_ptr serviceGetList(void); std::unique_ptr serviceGetListenerList(void); diff --git a/server/core/modulecmd.cc b/server/core/modulecmd.cc index 53d1ad326..4710e0f5d 100644 --- a/server/core/modulecmd.cc +++ b/server/core/modulecmd.cc @@ -27,6 +27,8 @@ /** Size of the error buffer */ #define MODULECMD_ERRBUF_SIZE 512 +using maxscale::Monitor; + /** Thread local error buffer */ thread_local char* errbuf = NULL; diff --git a/server/core/monitor.cc b/server/core/monitor.cc index a22bf3c30..d4026504f 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -70,6 +70,8 @@ enum stored_value_type using std::string; using std::set; using Guard = std::lock_guard; +using maxscale::Monitor; +using maxscale::MXS_MONITORED_SERVER; const char CN_BACKEND_CONNECT_ATTEMPTS[] = "backend_connect_attempts"; const char CN_BACKEND_CONNECT_TIMEOUT[] = "backend_connect_timeout"; @@ -397,6 +399,62 @@ bool process_data_file(Monitor* monitor, MXS_MONITORED_SERVER** master, return true; } +json_t* monitor_parameters_to_json(const Monitor* monitor) +{ + json_t* rval = json_object(); + const MXS_MODULE* mod = get_module(monitor->m_module.c_str(), MODULE_MONITOR); + config_add_module_params_json(&monitor->parameters, + {CN_TYPE, CN_MODULE, CN_SERVERS}, + config_monitor_params, + mod->parameters, + rval); + return rval; +} + +json_t* monitor_json_data(const Monitor* monitor, const char* host) +{ + json_t* rval = json_object(); + json_t* attr = json_object(); + json_t* rel = json_object(); + + { + Guard guard(monitor->m_lock); + json_object_set_new(rval, CN_ID, json_string(monitor->m_name)); + json_object_set_new(rval, CN_TYPE, json_string(CN_MONITORS)); + + json_object_set_new(attr, CN_MODULE, json_string(monitor->m_module.c_str())); + json_object_set_new(attr, CN_STATE, json_string(monitor_state_to_string(monitor->state()))); + json_object_set_new(attr, CN_TICKS, json_integer(monitor->m_ticks)); + + /** Monitor parameters */ + json_object_set_new(attr, CN_PARAMETERS, monitor_parameters_to_json(monitor)); + + if (monitor->state() == MONITOR_STATE_RUNNING) + { + json_t* diag = monitor->diagnostics_json(); + if (diag) + { + json_object_set_new(attr, CN_MONITOR_DIAGNOSTICS, diag); + } + } + + if (!monitor->m_servers.empty()) + { + json_t* mon_rel = mxs_json_relationship(host, MXS_JSON_API_SERVERS); + for (MXS_MONITORED_SERVER* db : monitor->m_servers) + { + mxs_json_add_relation(mon_rel, db->server->name(), CN_SERVERS); + } + json_object_set_new(rel, CN_SERVERS, mon_rel); + } + } + + json_object_set_new(rval, CN_RELATIONSHIPS, rel); + json_object_set_new(rval, CN_ATTRIBUTES, attr); + json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_MONITORS, monitor->m_name)); + return rval; +} + } Monitor* MonitorManager::create_monitor(const string& name, const string& module, @@ -429,6 +487,396 @@ Monitor* MonitorManager::create_monitor(const string& name, const string& module return mon; } +void MonitorManager::debug_wait_one_tick() +{ + using namespace std::chrono; + std::map ticks; + + // Get tick values for all monitors + this_unit.foreach_monitor([&ticks](Monitor* mon) { + ticks[mon] = mxb::atomic::load(&mon->m_ticks); + return true; + }); + + // Wait for all running monitors to advance at least one tick. + this_unit.foreach_monitor([&ticks](Monitor* mon) { + if (mon->state() == MONITOR_STATE_RUNNING) + { + auto start = steady_clock::now(); + // A monitor may have been added in between the two foreach-calls (not if config changes are + // serialized). Check if entry exists. + if (ticks.count(mon) > 0) + { + auto tick = ticks[mon]; + while (mxb::atomic::load(&mon->m_ticks) == tick && (steady_clock::now() - start < seconds(60))) + { + std::this_thread::sleep_for(milliseconds(100)); + } + } + } + return true; + }); +} + +void MonitorManager::destroy_all_monitors() +{ + auto monitors = this_unit.clear(); + for (auto monitor : monitors) + { + mxb_assert(monitor->state() == MONITOR_STATE_STOPPED); + delete monitor; + } +} + +void MonitorManager::start_monitor(Monitor* monitor) +{ + mxb_assert(monitor); + + Guard guard(monitor->m_lock); + + // Only start the monitor if it's stopped. + if (monitor->state() == MONITOR_STATE_STOPPED) + { + if (!monitor->start()) + { + MXS_ERROR("Failed to start monitor '%s'.", monitor->m_name); + } + } +} + +void MonitorManager::populate_services() +{ + this_unit.foreach_monitor([](Monitor* pMonitor) -> bool { + pMonitor->populate_services(); + return true; + }); +} + +/** + * Start all monitors + */ +void MonitorManager::start_all_monitors() +{ + this_unit.foreach_monitor([](Monitor* monitor) { + if (monitor->m_active) + { + MonitorManager::start_monitor(monitor); + } + return true; + }); +} + +void MonitorManager::stop_monitor(Monitor* monitor) +{ + mxb_assert(monitor); + + Guard guard(monitor->m_lock); + + /** Only stop the monitor if it is running */ + if (monitor->state() == MONITOR_STATE_RUNNING) + { + monitor->stop(); + } +} + +void MonitorManager::deactivate_monitor(Monitor* monitor) +{ + // This cannot be done with configure(), since other, module-specific config settings may depend on the + // "servers"-setting of the base monitor. Directly manipulate monitor field for now, later use a dtor + // to cleanly "deactivate" inherited objects. + stop_monitor(monitor); + while (!monitor->m_servers.empty()) + { + monitor->remove_server(monitor->m_servers.front()->server); + } + + this_unit.run_behind_lock([monitor](){ + monitor->m_active = false; + }); +} + +/** + * Shutdown all running monitors + */ +void MonitorManager::stop_all_monitors() +{ + this_unit.foreach_monitor([](Monitor* monitor) { + if (monitor->m_active) + { + MonitorManager::stop_monitor(monitor); + } + return true; + }); +} + +/** + * Show all monitors + * + * @param dcb DCB for printing output + */ +void MonitorManager::show_all_monitors(DCB* dcb) +{ + this_unit.foreach_monitor([dcb](Monitor* monitor) { + if (monitor->m_active) + { + monitor_show(dcb, monitor); + } + return true; + }); +} + +/** + * Show a single monitor + * + * @param dcb DCB for printing output + */ +void MonitorManager::monitor_show(DCB* dcb, Monitor* monitor) +{ + monitor->show(dcb); +} + +/** + * List all the monitors + * + * @param dcb DCB for printing output + */ +void MonitorManager::monitor_list(DCB* dcb) +{ + dcb_printf(dcb, "---------------------+---------------------\n"); + dcb_printf(dcb, "%-20s | Status\n", "Monitor"); + dcb_printf(dcb, "---------------------+---------------------\n"); + + this_unit.foreach_monitor([dcb](Monitor* ptr){ + if (ptr->m_active) + { + dcb_printf(dcb, + "%-20s | %s\n", + ptr->m_name, + ptr->state() == MONITOR_STATE_RUNNING ? + "Running" : "Stopped"); + } + return true; + }); + + dcb_printf(dcb, "---------------------+---------------------\n"); +} + +/** + * Find a monitor by name + * + * @param name The name of the monitor + * @return Pointer to the monitor or NULL + */ +Monitor* MonitorManager::find_monitor(const char* name) +{ + Monitor* rval = nullptr; + this_unit.foreach_monitor([&rval, name](Monitor* ptr) { + if (!strcmp(ptr->m_name, name) && ptr->m_active) + { + rval = ptr; + } + return (rval == nullptr); + }); + return rval; +} + +/** + * Find a destroyed monitor by name + * + * @param name The name of the monitor + * @return Pointer to the destroyed monitor or NULL if monitor is not found + */ +Monitor* MonitorManager::reactivate_monitor(const char* name, const char* module) +{ + Monitor* rval = NULL; + this_unit.foreach_monitor([&rval, name, module](Monitor* monitor) { + if (strcmp(monitor->m_name, name) == 0 && (monitor->m_module == module)) + { + mxb_assert(!monitor->m_active); + monitor->m_active = true; + rval = monitor; + } + return (rval == nullptr); + }); + return rval; +} + +/** + * Return a resultset that has the current set of monitors in it + * + * @return A Result set + */ +std::unique_ptr MonitorManager::monitor_get_list() +{ + std::unique_ptr set = ResultSet::create({"Monitor", "Status"}); + this_unit.foreach_monitor([&set](Monitor* ptr) { + const char* state = ptr->state() == MONITOR_STATE_RUNNING ? "Running" : "Stopped"; + set->add_row({ptr->m_name, state}); + return true; + }); + return set; +} + +Monitor* MonitorManager::server_is_monitored(const SERVER* server) +{ + Monitor* rval = nullptr; + this_unit.foreach_monitor([&rval, server](Monitor* monitor) { + Guard guard(monitor->m_lock); + if (monitor->m_active) + { + for (MXS_MONITORED_SERVER* db : monitor->m_servers) + { + if (db->server == server) + { + rval = monitor; + break; + } + } + } + return (rval == nullptr); + }); + return rval; +} + +bool MonitorManager::create_monitor_config(const Monitor* monitor, const char* filename) +{ + int file = open(filename, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (file == -1) + { + MXS_ERROR("Failed to open file '%s' when serializing monitor '%s': %d, %s", + filename, + monitor->m_name, + errno, + mxs_strerror(errno)); + return false; + } + + { + Guard guard(monitor->m_lock); + + const MXS_MODULE* mod = get_module(monitor->m_module.c_str(), NULL); + mxb_assert(mod); + + string config = generate_config_string(monitor->m_name, monitor->parameters, + config_monitor_params, mod->parameters); + + if (dprintf(file, "%s", config.c_str()) == -1) + { + MXS_ERROR("Could not write serialized configuration to file '%s': %d, %s", + filename, errno, mxs_strerror(errno)); + } + } + + close(file); + return true; +} + +bool MonitorManager::monitor_serialize(const Monitor* monitor) +{ + bool rval = false; + char filename[PATH_MAX]; + snprintf(filename, + sizeof(filename), + "%s/%s.cnf.tmp", + get_config_persistdir(), + monitor->m_name); + + if (unlink(filename) == -1 && errno != ENOENT) + { + MXS_ERROR("Failed to remove temporary monitor configuration at '%s': %d, %s", + filename, + errno, + mxs_strerror(errno)); + } + else if (create_monitor_config(monitor, filename)) + { + char final_filename[PATH_MAX]; + strcpy(final_filename, filename); + + char* dot = strrchr(final_filename, '.'); + mxb_assert(dot); + *dot = '\0'; + + if (rename(filename, final_filename) == 0) + { + rval = true; + } + else + { + MXS_ERROR("Failed to rename temporary monitor configuration at '%s': %d, %s", + filename, + errno, + mxs_strerror(errno)); + } + } + + return rval; +} + +json_t* MonitorManager::monitor_to_json(const Monitor* monitor, const char* host) +{ + string self = MXS_JSON_API_MONITORS; + self += monitor->m_name; + return mxs_json_resource(host, self.c_str(), monitor_json_data(monitor, host)); +} + +json_t* MonitorManager::monitor_list_to_json(const char* host) +{ + json_t* rval = json_array(); + this_unit.foreach_monitor([rval, host](Monitor* mon) { + if (mon->m_active) + { + json_t* json = monitor_json_data(mon, host); + + if (json) + { + json_array_append_new(rval, json); + } + } + return true; + }); + + return mxs_json_resource(host, MXS_JSON_API_MONITORS, rval); +} + +json_t* MonitorManager::monitor_relations_to_server(const SERVER* server, const char* host) +{ + std::vector names; + this_unit.foreach_monitor([&names, server](Monitor* mon) { + Guard guard(mon->m_lock); + if (mon->m_active) + { + for (MXS_MONITORED_SERVER* db : mon->m_servers) + { + if (db->server == server) + { + names.push_back(mon->m_name); + break; + } + } + } + return true; + }); + + json_t* rel = NULL; + if (!names.empty()) + { + rel = mxs_json_relationship(host, MXS_JSON_API_MONITORS); + + for (std::vector::iterator it = names.begin(); + it != names.end(); it++) + { + mxs_json_add_relation(rel, it->c_str(), CN_MONITORS); + } + } + + return rel; +} + + +namespace maxscale +{ + Monitor::Monitor(const string& name, const string& module) : m_name(MXS_STRDUP_A(name.c_str())) , m_module(module) @@ -522,97 +970,6 @@ Monitor::~Monitor() MXS_FREE((const_cast(m_name))); } -void MonitorManager::destroy_all_monitors() -{ - auto monitors = this_unit.clear(); - for (auto monitor : monitors) - { - mxb_assert(monitor->state() == MONITOR_STATE_STOPPED); - delete monitor; - } -} - -void MonitorManager::start_monitor(Monitor* monitor) -{ - mxb_assert(monitor); - - Guard guard(monitor->m_lock); - - // Only start the monitor if it's stopped. - if (monitor->state() == MONITOR_STATE_STOPPED) - { - if (!monitor->start()) - { - MXS_ERROR("Failed to start monitor '%s'.", monitor->m_name); - } - } -} - -void MonitorManager::populate_services() -{ - this_unit.foreach_monitor([](Monitor* pMonitor) -> bool { - pMonitor->populate_services(); - return true; - }); -} - -/** - * Start all monitors - */ -void MonitorManager::start_all_monitors() -{ - this_unit.foreach_monitor([](Monitor* monitor) { - if (monitor->m_active) - { - MonitorManager::start_monitor(monitor); - } - return true; - }); -} - -void MonitorManager::stop_monitor(Monitor* monitor) -{ - mxb_assert(monitor); - - Guard guard(monitor->m_lock); - - /** Only stop the monitor if it is running */ - if (monitor->state() == MONITOR_STATE_RUNNING) - { - monitor->stop(); - } -} - -void MonitorManager::deactivate_monitor(Monitor* monitor) -{ - // This cannot be done with configure(), since other, module-specific config settings may depend on the - // "servers"-setting of the base monitor. Directly manipulate monitor field for now, later use a dtor - // to cleanly "deactivate" inherited objects. - stop_monitor(monitor); - while (!monitor->m_servers.empty()) - { - monitor->remove_server(monitor->m_servers.front()->server); - } - - this_unit.run_behind_lock([monitor](){ - monitor->m_active = false; - }); -} - -/** - * Shutdown all running monitors - */ -void MonitorManager::stop_all_monitors() -{ - this_unit.foreach_monitor([](Monitor* monitor) { - if (monitor->m_active) - { - MonitorManager::stop_monitor(monitor); - } - return true; - }); -} - /** * @brief Add a server to the monitor. * @@ -681,32 +1038,6 @@ void Monitor::remove_server(SERVER* server) } } -/** - * Show all monitors - * - * @param dcb DCB for printing output - */ -void MonitorManager::show_all_monitors(DCB* dcb) -{ - this_unit.foreach_monitor([dcb](Monitor* monitor) { - if (monitor->m_active) - { - monitor_show(dcb, monitor); - } - return true; - }); -} - -/** - * Show a single monitor - * - * @param dcb DCB for printing output - */ -void MonitorManager::monitor_show(DCB* dcb, Monitor* monitor) -{ - monitor->show(dcb); -} - void Monitor::show(DCB* dcb) { Monitor* monitor = this; @@ -742,87 +1073,6 @@ void Monitor::show(DCB* dcb) dcb_printf(dcb, "\n"); } -/** - * List all the monitors - * - * @param dcb DCB for printing output - */ -void MonitorManager::monitor_list(DCB* dcb) -{ - dcb_printf(dcb, "---------------------+---------------------\n"); - dcb_printf(dcb, "%-20s | Status\n", "Monitor"); - dcb_printf(dcb, "---------------------+---------------------\n"); - - this_unit.foreach_monitor([dcb](Monitor* ptr){ - if (ptr->m_active) - { - dcb_printf(dcb, - "%-20s | %s\n", - ptr->m_name, - ptr->state() == MONITOR_STATE_RUNNING ? - "Running" : "Stopped"); - } - return true; - }); - - dcb_printf(dcb, "---------------------+---------------------\n"); -} - -/** - * Find a monitor by name - * - * @param name The name of the monitor - * @return Pointer to the monitor or NULL - */ -Monitor* MonitorManager::find_monitor(const char* name) -{ - Monitor* rval = nullptr; - this_unit.foreach_monitor([&rval, name](Monitor* ptr) { - if (!strcmp(ptr->m_name, name) && ptr->m_active) - { - rval = ptr; - } - return (rval == nullptr); - }); - return rval; -} -/** - * Find a destroyed monitor by name - * - * @param name The name of the monitor - * @return Pointer to the destroyed monitor or NULL if monitor is not found - */ -Monitor* MonitorManager::reactivate_monitor(const char* name, const char* module) -{ - Monitor* rval = NULL; - this_unit.foreach_monitor([&rval, name, module](Monitor* monitor) { - if (strcmp(monitor->m_name, name) == 0 && (monitor->m_module == module)) - { - mxb_assert(!monitor->m_active); - monitor->m_active = true; - rval = monitor; - } - return (rval == nullptr); - }); - return rval; -} - -/** - * Return a resultset that has the current set of monitors in it - * - * @return A Result set - */ -std::unique_ptr MonitorManager::monitor_get_list() -{ - std::unique_ptr set = ResultSet::create({"Monitor", "Status"}); - this_unit.foreach_monitor([&set](Monitor* ptr) { - const char* state = ptr->state() == MONITOR_STATE_RUNNING ? "Running" : "Stopped"; - set->add_row({ptr->m_name, state}); - return true; - }); - return set; -} - bool Monitor::test_permissions(const string& query) { auto monitor = this; @@ -1476,102 +1726,6 @@ void MXS_MONITORED_SERVER::log_state_change() prev.c_str(), next.c_str()); } -Monitor* MonitorManager::server_is_monitored(const SERVER* server) -{ - Monitor* rval = nullptr; - this_unit.foreach_monitor([&rval, server](Monitor* monitor) { - Guard guard(monitor->m_lock); - if (monitor->m_active) - { - for (MXS_MONITORED_SERVER* db : monitor->m_servers) - { - if (db->server == server) - { - rval = monitor; - break; - } - } - } - return (rval == nullptr); - }); - return rval; -} - -bool MonitorManager::create_monitor_config(const Monitor* monitor, const char* filename) -{ - int file = open(filename, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (file == -1) - { - MXS_ERROR("Failed to open file '%s' when serializing monitor '%s': %d, %s", - filename, - monitor->m_name, - errno, - mxs_strerror(errno)); - return false; - } - - { - Guard guard(monitor->m_lock); - - const MXS_MODULE* mod = get_module(monitor->m_module.c_str(), NULL); - mxb_assert(mod); - - string config = generate_config_string(monitor->m_name, monitor->parameters, - config_monitor_params, mod->parameters); - - if (dprintf(file, "%s", config.c_str()) == -1) - { - MXS_ERROR("Could not write serialized configuration to file '%s': %d, %s", - filename, errno, mxs_strerror(errno)); - } - } - - close(file); - return true; -} - -bool MonitorManager::monitor_serialize(const Monitor* monitor) -{ - bool rval = false; - char filename[PATH_MAX]; - snprintf(filename, - sizeof(filename), - "%s/%s.cnf.tmp", - get_config_persistdir(), - monitor->m_name); - - if (unlink(filename) == -1 && errno != ENOENT) - { - MXS_ERROR("Failed to remove temporary monitor configuration at '%s': %d, %s", - filename, - errno, - mxs_strerror(errno)); - } - else if (create_monitor_config(monitor, filename)) - { - char final_filename[PATH_MAX]; - strcpy(final_filename, filename); - - char* dot = strrchr(final_filename, '.'); - mxb_assert(dot); - *dot = '\0'; - - if (rename(filename, final_filename) == 0) - { - rval = true; - } - else - { - MXS_ERROR("Failed to rename temporary monitor configuration at '%s': %d, %s", - filename, - errno, - mxs_strerror(errno)); - } - } - - return rval; -} - void Monitor::hangup_failed_servers() { for (MXS_MONITORED_SERVER* ptr : m_servers) @@ -1682,122 +1836,6 @@ void Monitor::detect_handle_state_changes() } } -json_t* monitor_parameters_to_json(const Monitor* monitor) -{ - json_t* rval = json_object(); - const MXS_MODULE* mod = get_module(monitor->m_module.c_str(), MODULE_MONITOR); - config_add_module_params_json(&monitor->parameters, - {CN_TYPE, CN_MODULE, CN_SERVERS}, - config_monitor_params, - mod->parameters, - rval); - return rval; -} - -json_t* monitor_json_data(const Monitor* monitor, const char* host) -{ - json_t* rval = json_object(); - json_t* attr = json_object(); - json_t* rel = json_object(); - - { - Guard guard(monitor->m_lock); - json_object_set_new(rval, CN_ID, json_string(monitor->m_name)); - json_object_set_new(rval, CN_TYPE, json_string(CN_MONITORS)); - - json_object_set_new(attr, CN_MODULE, json_string(monitor->m_module.c_str())); - json_object_set_new(attr, CN_STATE, json_string(monitor_state_to_string(monitor->state()))); - json_object_set_new(attr, CN_TICKS, json_integer(monitor->m_ticks)); - - /** Monitor parameters */ - json_object_set_new(attr, CN_PARAMETERS, monitor_parameters_to_json(monitor)); - - if (monitor->state() == MONITOR_STATE_RUNNING) - { - json_t* diag = monitor->diagnostics_json(); - if (diag) - { - json_object_set_new(attr, CN_MONITOR_DIAGNOSTICS, diag); - } - } - - if (!monitor->m_servers.empty()) - { - json_t* mon_rel = mxs_json_relationship(host, MXS_JSON_API_SERVERS); - for (MXS_MONITORED_SERVER* db : monitor->m_servers) - { - mxs_json_add_relation(mon_rel, db->server->name(), CN_SERVERS); - } - json_object_set_new(rel, CN_SERVERS, mon_rel); - } - } - - json_object_set_new(rval, CN_RELATIONSHIPS, rel); - json_object_set_new(rval, CN_ATTRIBUTES, attr); - json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_MONITORS, monitor->m_name)); - return rval; -} - -json_t* MonitorManager::monitor_to_json(const Monitor* monitor, const char* host) -{ - string self = MXS_JSON_API_MONITORS; - self += monitor->m_name; - return mxs_json_resource(host, self.c_str(), monitor_json_data(monitor, host)); -} - -json_t* MonitorManager::monitor_list_to_json(const char* host) -{ - json_t* rval = json_array(); - this_unit.foreach_monitor([rval, host](Monitor* mon) { - if (mon->m_active) - { - json_t* json = monitor_json_data(mon, host); - - if (json) - { - json_array_append_new(rval, json); - } - } - return true; - }); - - return mxs_json_resource(host, MXS_JSON_API_MONITORS, rval); -} - -json_t* MonitorManager::monitor_relations_to_server(const SERVER* server, const char* host) -{ - std::vector names; - this_unit.foreach_monitor([&names, server](Monitor* mon) { - Guard guard(mon->m_lock); - if (mon->m_active) - { - for (MXS_MONITORED_SERVER* db : mon->m_servers) - { - if (db->server == server) - { - names.push_back(mon->m_name); - break; - } - } - } - return true; - }); - - json_t* rel = NULL; - if (!names.empty()) - { - rel = mxs_json_relationship(host, MXS_JSON_API_MONITORS); - - for (std::vector::iterator it = names.begin(); - it != names.end(); it++) - { - mxs_json_add_relation(rel, it->c_str(), CN_MONITORS); - } - } - - return rel; -} - int Monitor::get_data_file_path(char* path) const { int rv = snprintf(path, PATH_MAX, journal_template, get_datadir(), m_name, journal_name); @@ -2244,40 +2282,6 @@ void Monitor::populate_services() } } -void MonitorManager::debug_wait_one_tick() -{ - using namespace std::chrono; - std::map ticks; - - // Get tick values for all monitors - this_unit.foreach_monitor([&ticks](Monitor* mon) { - ticks[mon] = mxb::atomic::load(&mon->m_ticks); - return true; - }); - - // Wait for all running monitors to advance at least one tick. - this_unit.foreach_monitor([&ticks](Monitor* mon) { - if (mon->state() == MONITOR_STATE_RUNNING) - { - auto start = steady_clock::now(); - // A monitor may have been added in between the two foreach-calls (not if config changes are - // serialized). Check if entry exists. - if (ticks.count(mon) > 0) - { - auto tick = ticks[mon]; - while (mxb::atomic::load(&mon->m_ticks) == tick && (steady_clock::now() - start < seconds(60))) - { - std::this_thread::sleep_for(milliseconds(100)); - } - } - } - return true; - }); -} - -namespace maxscale -{ - MonitorWorker::MonitorWorker(const string& name, const string& module) : Monitor(name, module) , m_master(NULL) diff --git a/server/core/resource.cc b/server/core/resource.cc index e0b334ce4..8dd5fd638 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -40,6 +40,7 @@ using std::list; using std::map; using std::string; using std::stringstream; +using maxscale::Monitor; Resource::Resource(ResourceCallback cb, int components, ...) : m_cb(cb) diff --git a/server/core/server.cc b/server/core/server.cc index aa14f7ba3..32ee88129 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -53,6 +53,7 @@ using maxbase::Worker; using maxscale::RoutingWorker; +using maxscale::Monitor; using std::string; using Guard = std::lock_guard; @@ -480,7 +481,7 @@ void Server::print_to_dcb(DCB* dcb) const dcb_printf(dcb, "\tMaster Id: %ld\n", server->master_id); dcb_printf(dcb, "\tLast event: %s\n", - Monitor::get_event_name((mxs_monitor_event_t) server->last_event)); + mxs::Monitor::get_event_name((mxs_monitor_event_t) server->last_event)); time_t t = maxscale_started() + MXS_CLOCK_TO_SEC(server->triggered_at); dcb_printf(dcb, "\tTriggered at: %s\n", http_to_date(t).c_str()); if (server->is_slave() || server->is_relay()) diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index 586c95240..234a91f32 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -24,6 +24,7 @@ #include #include +using maxscale::MXS_MONITORED_SERVER; AuroraMonitor::AuroraMonitor(const std::string& name, const std::string& module) : MonitorWorkerSimple(name, module) diff --git a/server/modules/monitor/auroramon/auroramon.hh b/server/modules/monitor/auroramon/auroramon.hh index 3dc70f217..af28f5fc5 100644 --- a/server/modules/monitor/auroramon/auroramon.hh +++ b/server/modules/monitor/auroramon/auroramon.hh @@ -30,7 +30,7 @@ public: protected: bool has_sufficient_permissions(); - void update_server_status(MXS_MONITORED_SERVER* monitored_server); + void update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server); private: AuroraMonitor(const std::string& name, const std::string& module); diff --git a/server/modules/monitor/clustrixmon/clustrix.cc b/server/modules/monitor/clustrixmon/clustrix.cc index 0675cb779..1208bb5ba 100644 --- a/server/modules/monitor/clustrixmon/clustrix.cc +++ b/server/modules/monitor/clustrixmon/clustrix.cc @@ -14,6 +14,9 @@ #include "clustrix.hh" #include +using maxscale::Monitor; +using maxscale::MXS_MONITORED_SERVER; + namespace { diff --git a/server/modules/monitor/clustrixmon/clustrix.hh b/server/modules/monitor/clustrixmon/clustrix.hh index ee88ee0f5..9b7d8a70f 100644 --- a/server/modules/monitor/clustrixmon/clustrix.hh +++ b/server/modules/monitor/clustrixmon/clustrix.hh @@ -65,7 +65,7 @@ bool is_part_of_the_quorum(const char* zName, const SERVER& server, MYSQL* pCon) * * @return True, if the node is part of the quorum, false otherwise. */ -inline bool is_part_of_the_quorum(const char* zName, MXS_MONITORED_SERVER& ms) +inline bool is_part_of_the_quorum(const char* zName, mxs::MXS_MONITORED_SERVER& ms) { mxb_assert(ms.server); mxb_assert(ms.con); @@ -100,7 +100,7 @@ bool is_being_softfailed(const char* zName, const SERVER& server, MYSQL* pCon); * @note Upon return @c *ppCon will be non-NULL. */ bool ping_or_connect_to_hub(const char* zName, - const MXS_MONITORED_SERVER::ConnectionSettings& settings, + const mxs::MXS_MONITORED_SERVER::ConnectionSettings& settings, Softfailed softfailed, SERVER& server, MYSQL** ppCon); @@ -117,9 +117,9 @@ bool ping_or_connect_to_hub(const char* zName, * @return True, if the server can be used as hub, false otherwise. */ inline bool ping_or_connect_to_hub(const char* zName, - const MXS_MONITORED_SERVER::ConnectionSettings& settings, + const mxs::MXS_MONITORED_SERVER::ConnectionSettings& settings, Softfailed softfailed, - MXS_MONITORED_SERVER& ms) + mxs::MXS_MONITORED_SERVER& ms) { return ping_or_connect_to_hub(zName, settings, softfailed, *ms.server, &ms.con); } diff --git a/server/modules/monitor/clustrixmon/clustrixmonitor.cc b/server/modules/monitor/clustrixmon/clustrixmonitor.cc index 85d2b590d..a13a9e2ec 100644 --- a/server/modules/monitor/clustrixmon/clustrixmonitor.cc +++ b/server/modules/monitor/clustrixmon/clustrixmonitor.cc @@ -20,6 +20,7 @@ namespace http = mxb::http; using namespace std; +using maxscale::MXS_MONITORED_SERVER; #define LOG_JSON_ERROR(ppJson, format, ...) \ do { \ diff --git a/server/modules/monitor/clustrixmon/clustrixnode.cc b/server/modules/monitor/clustrixmon/clustrixnode.cc index bcb9889d0..33b7dbab2 100644 --- a/server/modules/monitor/clustrixmon/clustrixnode.cc +++ b/server/modules/monitor/clustrixmon/clustrixnode.cc @@ -15,7 +15,7 @@ #include "clustrix.hh" bool ClustrixNode::can_be_used_as_hub(const char* zName, - const MXS_MONITORED_SERVER::ConnectionSettings& settings) + const mxs::MXS_MONITORED_SERVER::ConnectionSettings& settings) { mxb_assert(m_pServer); bool rv = Clustrix::ping_or_connect_to_hub(zName, settings, Clustrix::Softfailed::REJECT, diff --git a/server/modules/monitor/clustrixmon/clustrixnode.hh b/server/modules/monitor/clustrixmon/clustrixnode.hh index d5559d1bd..2c0d4fabd 100644 --- a/server/modules/monitor/clustrixmon/clustrixnode.hh +++ b/server/modules/monitor/clustrixmon/clustrixnode.hh @@ -161,7 +161,7 @@ public: } bool can_be_used_as_hub(const char* zName, - const MXS_MONITORED_SERVER::ConnectionSettings& settings); + const mxs::MXS_MONITORED_SERVER::ConnectionSettings& settings); SERVER* server() const { diff --git a/server/modules/monitor/csmon/csmon.cc b/server/modules/monitor/csmon/csmon.cc index 524ae3144..01a02ee2f 100644 --- a/server/modules/monitor/csmon/csmon.cc +++ b/server/modules/monitor/csmon/csmon.cc @@ -22,6 +22,8 @@ #include #include +using maxscale::MXS_MONITORED_SERVER; + namespace { diff --git a/server/modules/monitor/csmon/csmon.hh b/server/modules/monitor/csmon/csmon.hh index 59357b52a..1a7a79e96 100644 --- a/server/modules/monitor/csmon/csmon.hh +++ b/server/modules/monitor/csmon/csmon.hh @@ -26,7 +26,7 @@ public: protected: bool has_sufficient_permissions(); - void update_server_status(MXS_MONITORED_SERVER* monitored_server); + void update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server); private: CsMonitor(const std::string& name, const std::string& module); diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index 6acadba0e..58e549355 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -33,6 +33,8 @@ #define DONOR_NODE_NAME_MAX_LEN 60 #define DONOR_LIST_SET_VAR "SET GLOBAL wsrep_sst_donor = \"" +using maxscale::MXS_MONITORED_SERVER; + /** Log a warning when a bad 'wsrep_local_index' is found */ static bool warn_erange_on_local_index = true; diff --git a/server/modules/monitor/galeramon/galeramon.hh b/server/modules/monitor/galeramon/galeramon.hh index 5c8e0b3b2..8e8bb71a5 100644 --- a/server/modules/monitor/galeramon/galeramon.hh +++ b/server/modules/monitor/galeramon/galeramon.hh @@ -32,7 +32,7 @@ struct GaleraNode std::string cluster_uuid; /**< Cluster UUID */ }; -typedef std::unordered_map NodeMap; +typedef std::unordered_map NodeMap; class GaleraMonitor : public maxscale::MonitorWorkerSimple { @@ -48,7 +48,7 @@ public: protected: bool configure(const MXS_CONFIG_PARAMETER* param); bool has_sufficient_permissions(); - void update_server_status(MXS_MONITORED_SERVER* monitored_server); + void update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server); void pre_tick(); void post_tick(); @@ -71,7 +71,7 @@ private: bool detect_cluster_size(const int n_nodes, const char* candidate_uuid, const int candidate_size); - MXS_MONITORED_SERVER* get_candidate_master(); + mxs::MXS_MONITORED_SERVER* get_candidate_master(); void set_galera_cluster(); void update_sst_donor_nodes(int is_cluster); }; diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index e48b66c1c..dc5c18e34 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -25,6 +25,7 @@ #include #include +using maxscale::MXS_MONITORED_SERVER; GRMon::GRMon(const std::string& name, const std::string& module) : MonitorWorkerSimple(name, module) diff --git a/server/modules/monitor/grmon/grmon.hh b/server/modules/monitor/grmon/grmon.hh index 70c9b462a..918551163 100644 --- a/server/modules/monitor/grmon/grmon.hh +++ b/server/modules/monitor/grmon/grmon.hh @@ -30,7 +30,7 @@ public: protected: bool has_sufficient_permissions(); - void update_server_status(MXS_MONITORED_SERVER* monitored_server); + void update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server); private: GRMon(const std::string& name, const std::string& module); diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index 9450e86b0..73c6b2dc6 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -32,6 +32,8 @@ using std::string; using maxbase::string_printf; +using maxscale::Monitor; +using maxscale::MXS_MONITORED_SERVER; // Config parameter names const char* const CN_AUTO_FAILOVER = "auto_failover"; diff --git a/server/modules/monitor/mariadbmon/mariadbmon.hh b/server/modules/monitor/mariadbmon/mariadbmon.hh index a50b51b44..69a3847f2 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.hh +++ b/server/modules/monitor/mariadbmon/mariadbmon.hh @@ -251,7 +251,7 @@ private: MariaDBServer* get_server(const std::string& host, int port); MariaDBServer* get_server(int64_t id); - MariaDBServer* get_server(MXS_MONITORED_SERVER* mon_server); + MariaDBServer* get_server(mxs::MXS_MONITORED_SERVER* mon_server); MariaDBServer* get_server(SERVER* server); // Cluster discovery and status assignment methods, top levels diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index c5d842575..64e3771dd 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -28,6 +28,7 @@ using maxbase::Duration; using maxbase::StopWatch; using maxsql::QueryResult; using Guard = std::lock_guard; +using maxscale::MXS_MONITORED_SERVER; MariaDBServer::MariaDBServer(MXS_MONITORED_SERVER* monitored_server, int config_index, bool assume_unique_hostnames, bool query_events) diff --git a/server/modules/monitor/mariadbmon/mariadbserver.hh b/server/modules/monitor/mariadbmon/mariadbserver.hh index a8dbab3fb..18729781b 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.hh +++ b/server/modules/monitor/mariadbmon/mariadbserver.hh @@ -73,7 +73,7 @@ struct NodeData class MariaDBServer { public: - MariaDBServer(MXS_MONITORED_SERVER* monitored_server, int config_index, + MariaDBServer(mxs::MXS_MONITORED_SERVER* monitored_server, int config_index, bool assume_unique_hostnames, bool query_events); class EventInfo @@ -119,7 +119,7 @@ public: /* Monitored server base class/struct. MariaDBServer does not own the struct, it is not freed * (or connection closed) when a MariaDBServer is destroyed. */ - MXS_MONITORED_SERVER* m_server_base = NULL; + mxs::MXS_MONITORED_SERVER* m_server_base = NULL; /* What position this server has in the monitor config? Used for tiebreaking between servers. */ int m_config_index = 0; diff --git a/server/modules/monitor/mariadbmon/test/test_cycle_find.cc b/server/modules/monitor/mariadbmon/test/test_cycle_find.cc index acbff3ce0..71b8628bd 100644 --- a/server/modules/monitor/mariadbmon/test/test_cycle_find.cc +++ b/server/modules/monitor/mariadbmon/test/test_cycle_find.cc @@ -25,6 +25,7 @@ using std::string; using std::cout; +using maxscale::MXS_MONITORED_SERVER; // Maximum sizes for array types const int MAX_CYCLE_SIZE = 10; diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index e976872a1..f62be99f6 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -42,7 +42,7 @@ bool NDBCMonitor::has_sufficient_permissions() return test_permissions("SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'"); } -void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) +void NDBCMonitor::update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server) { MYSQL_ROW row; MYSQL_RES* result; diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.hh b/server/modules/monitor/ndbclustermon/ndbclustermon.hh index e6f26c6ab..919445636 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.hh +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.hh @@ -30,7 +30,7 @@ public: protected: bool has_sufficient_permissions(); - void update_server_status(MXS_MONITORED_SERVER* monitored_server); + void update_server_status(mxs::MXS_MONITORED_SERVER* monitored_server); private: NDBCMonitor(const std::string& name, const std::string& module); diff --git a/server/modules/routing/debugcli/debugcmd.cc b/server/modules/routing/debugcli/debugcmd.cc index 87d064eb5..507700326 100644 --- a/server/modules/routing/debugcli/debugcmd.cc +++ b/server/modules/routing/debugcli/debugcmd.cc @@ -80,6 +80,8 @@ #define ARG_TYPE_NUMERIC 10 #define ARG_TYPE_OBJECT_NAME 11 // A string where whitespace is replaced with hyphens +using maxscale::Monitor; + /** * The subcommand structure * diff --git a/server/modules/routing/maxinfo/maxinfo_exec.cc b/server/modules/routing/maxinfo/maxinfo_exec.cc index c2d005e3c..0fbdbc2d0 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.cc +++ b/server/modules/routing/maxinfo/maxinfo_exec.cc @@ -503,7 +503,7 @@ void exec_shutdown_monitor(DCB* dcb, MAXINFO_TREE* tree) char errmsg[120]; if (tree && tree->value) { - Monitor* monitor = MonitorManager::find_monitor(tree->value); + mxs::Monitor* monitor = MonitorManager::find_monitor(tree->value); if (monitor) { MonitorManager::stop_monitor(monitor); @@ -612,7 +612,7 @@ void exec_restart_monitor(DCB* dcb, MAXINFO_TREE* tree) char errmsg[120]; if (tree && tree->value) { - Monitor* monitor = MonitorManager::find_monitor(tree->value); + mxs::Monitor* monitor = MonitorManager::find_monitor(tree->value); if (monitor) { MonitorManager::start_monitor(monitor);