MXS-2540 Use new conf. mech. in Clustrix monitor
This commit is contained in:
@ -99,30 +99,9 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
NULL, /* Process finish. */
|
||||
NULL, /* Thread init. */
|
||||
NULL, /* Thread finish. */
|
||||
{
|
||||
{
|
||||
CLUSTER_MONITOR_INTERVAL_NAME,
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
DEFAULT_CLUSTER_MONITOR_INTERVAL_ZVALUE
|
||||
},
|
||||
{
|
||||
HEALTH_CHECK_THRESHOLD_NAME,
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
DEFAULT_HEALTH_CHECK_THRESHOLD_ZVALUE
|
||||
},
|
||||
{
|
||||
DYNAMIC_NODE_DETECTION_NAME,
|
||||
MXS_MODULE_PARAM_BOOL,
|
||||
DEFAULT_DYNAMIC_NODE_DETECTION_ZVALUE
|
||||
},
|
||||
{
|
||||
HEALTH_CHECK_PORT_NAME,
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
DEFAULT_HEALTH_CHECK_PORT_ZVALUE
|
||||
},
|
||||
{MXS_END_MODULE_PARAMS}
|
||||
}
|
||||
};
|
||||
|
||||
ClustrixMonitor::Config::populate(info);
|
||||
|
||||
return &info;
|
||||
}
|
||||
|
@ -17,18 +17,7 @@
|
||||
#include <maxscale/ccdefs.hh>
|
||||
#include <maxbase/log.hh>
|
||||
|
||||
#define CLUSTER_MONITOR_INTERVAL_NAME "cluster_monitor_interval"
|
||||
const long DEFAULT_CLUSTER_MONITOR_INTERVAL_VALUE = 60000;
|
||||
#define DEFAULT_CLUSTER_MONITOR_INTERVAL_ZVALUE "60000"
|
||||
|
||||
#define HEALTH_CHECK_THRESHOLD_NAME "health_check_threshold"
|
||||
const long DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE = 2;
|
||||
#define DEFAULT_HEALTH_CHECK_THRESHOLD_ZVALUE "2"
|
||||
|
||||
#define DYNAMIC_NODE_DETECTION_NAME "dynamic_node_detection"
|
||||
const bool DEFAULT_DYNAMIC_NODE_DETECTION_VALUE = true;
|
||||
#define DEFAULT_DYNAMIC_NODE_DETECTION_ZVALUE "true"
|
||||
|
||||
#define HEALTH_CHECK_PORT_NAME "health_check_port"
|
||||
const long DEFAULT_HEALTH_CHECK_PORT_VALUE = 3581;
|
||||
#define DEFAULT_HEALTH_CHECK_PORT_ZVALUE "3581"
|
||||
const long DEFAULT_CLUSTER_MONITOR_INTERVAL = 60000;
|
||||
const long DEFAULT_HEALTH_CHECK_THRESHOLD = 2;
|
||||
const bool DEFAULT_DYNAMIC_NODE_DETECTION = true;
|
||||
const long DEFAULT_HEALTH_CHECK_PORT = 3581;
|
||||
|
@ -38,6 +38,40 @@ using maxscale::MonitorServer;
|
||||
namespace
|
||||
{
|
||||
|
||||
namespace clustrixmon
|
||||
{
|
||||
|
||||
config::Specification specification(MXS_MODULE_NAME, config::Specification::MONITOR);
|
||||
|
||||
config::ParamDuration<std::chrono::milliseconds>
|
||||
cluster_monitor_interval(&specification,
|
||||
"cluster_monitor_interval",
|
||||
"How frequently the Clustrix monitor should perform a cluster check.",
|
||||
mxs::config::INTERPRET_AS_MILLISECONDS,
|
||||
std::chrono::milliseconds(DEFAULT_CLUSTER_MONITOR_INTERVAL));
|
||||
|
||||
config::ParamCount
|
||||
health_check_threshold(&specification,
|
||||
"health_check_threshold",
|
||||
"How many failed health port pings before node is assumed to be down.",
|
||||
DEFAULT_HEALTH_CHECK_THRESHOLD,
|
||||
1, std::numeric_limits<uint32_t>::max()); // min, max
|
||||
|
||||
config::ParamBool
|
||||
dynamic_node_detection(&specification,
|
||||
"dynamic_node_detection",
|
||||
"Should cluster configuration be figured out at runtime.",
|
||||
DEFAULT_DYNAMIC_NODE_DETECTION);
|
||||
|
||||
config::ParamInteger
|
||||
health_check_port(&specification,
|
||||
"health_check_port",
|
||||
"Port number for Clustrix health check.",
|
||||
DEFAULT_HEALTH_CHECK_PORT,
|
||||
0, std::numeric_limits<uint16_t>::max()); // min, max
|
||||
|
||||
}
|
||||
|
||||
const int DEFAULT_MYSQL_PORT = 3306;
|
||||
const int DEFAULT_HEALTH_PORT = 3581;
|
||||
|
||||
@ -156,6 +190,26 @@ sqlite3* open_or_create_db(const std::string& path)
|
||||
}
|
||||
}
|
||||
|
||||
ClustrixMonitor::Config::Config()
|
||||
: m_configuration(&clustrixmon::specification)
|
||||
, m_cluster_monitor_interval(&m_configuration, &clustrixmon::cluster_monitor_interval)
|
||||
, m_health_check_threshold(&m_configuration, &clustrixmon::health_check_threshold)
|
||||
, m_dynamic_node_detection(&m_configuration, &clustrixmon::dynamic_node_detection)
|
||||
, m_health_check_port(&m_configuration, &clustrixmon::health_check_port)
|
||||
{
|
||||
}
|
||||
|
||||
//static
|
||||
void ClustrixMonitor::Config::populate(MXS_MODULE& module)
|
||||
{
|
||||
clustrixmon::specification.populate(module);
|
||||
}
|
||||
|
||||
bool ClustrixMonitor::Config::configure(const MXS_CONFIG_PARAMETER& params)
|
||||
{
|
||||
return clustrixmon::specification.configure(m_configuration, params);
|
||||
}
|
||||
|
||||
ClustrixMonitor::ClustrixMonitor(const string& name, const string& module, sqlite3* pDb)
|
||||
: MonitorWorker(name, module)
|
||||
, m_pDb(pDb)
|
||||
@ -212,6 +266,11 @@ using std::chrono::milliseconds;
|
||||
|
||||
bool ClustrixMonitor::configure(const MXS_CONFIG_PARAMETER* pParams)
|
||||
{
|
||||
if (!clustrixmon::specification.validate(*pParams))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MonitorWorker::configure(pParams))
|
||||
{
|
||||
return false;
|
||||
@ -222,11 +281,9 @@ bool ClustrixMonitor::configure(const MXS_CONFIG_PARAMETER* pParams)
|
||||
m_health_urls.clear();
|
||||
m_nodes_by_id.clear();
|
||||
|
||||
long interval = pParams->get_duration<milliseconds>(CLUSTER_MONITOR_INTERVAL_NAME).count();
|
||||
m_config.set_cluster_monitor_interval(interval);
|
||||
m_config.set_health_check_threshold(pParams->get_integer(HEALTH_CHECK_THRESHOLD_NAME));
|
||||
m_config.set_dynamic_node_detection(pParams->get_bool(DYNAMIC_NODE_DETECTION_NAME));
|
||||
m_config.set_health_check_port(pParams->get_integer(HEALTH_CHECK_PORT_NAME));
|
||||
// Since they were validated above, failure should not be an option now.
|
||||
MXB_AT_DEBUG(bool configured=) m_config.configure(*pParams);
|
||||
mxb_assert(configured);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sqlite3.h>
|
||||
#include <maxscale/config2.hh>
|
||||
#include <maxscale/monitor.hh>
|
||||
#include <maxbase/http.hh>
|
||||
#include "clustrixmembership.hh"
|
||||
@ -30,59 +31,38 @@ public:
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
Config()
|
||||
: m_cluster_monitor_interval(DEFAULT_CLUSTER_MONITOR_INTERVAL_VALUE)
|
||||
, m_health_check_threshold(DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE)
|
||||
, m_dynamic_node_detection(DEFAULT_DYNAMIC_NODE_DETECTION_VALUE)
|
||||
, m_health_check_port(DEFAULT_HEALTH_CHECK_PORT_VALUE)
|
||||
{
|
||||
}
|
||||
Config();
|
||||
|
||||
static void populate(MXS_MODULE& module);
|
||||
|
||||
bool configure(const MXS_CONFIG_PARAMETER& params);
|
||||
|
||||
long cluster_monitor_interval() const
|
||||
{
|
||||
return m_cluster_monitor_interval;
|
||||
}
|
||||
|
||||
void set_cluster_monitor_interval(long l)
|
||||
{
|
||||
m_cluster_monitor_interval = l;
|
||||
return m_cluster_monitor_interval.count();
|
||||
}
|
||||
|
||||
long health_check_threshold() const
|
||||
{
|
||||
return m_health_check_threshold;
|
||||
}
|
||||
|
||||
void set_health_check_threshold(long l)
|
||||
{
|
||||
m_health_check_threshold = l;
|
||||
return m_health_check_threshold.get();
|
||||
}
|
||||
|
||||
bool dynamic_node_detection() const
|
||||
{
|
||||
return m_dynamic_node_detection;
|
||||
}
|
||||
|
||||
void set_dynamic_node_detection(bool b)
|
||||
{
|
||||
m_dynamic_node_detection = b;
|
||||
return static_cast<bool>(m_dynamic_node_detection);
|
||||
}
|
||||
|
||||
int health_check_port() const
|
||||
{
|
||||
return m_health_check_port;
|
||||
}
|
||||
|
||||
void set_health_check_port(int p)
|
||||
{
|
||||
m_health_check_port = p;
|
||||
return m_health_check_port.get();
|
||||
}
|
||||
|
||||
private:
|
||||
long m_cluster_monitor_interval;
|
||||
long m_health_check_threshold;
|
||||
bool m_dynamic_node_detection;
|
||||
int m_health_check_port;
|
||||
config::Configuration m_configuration;
|
||||
config::Duration<std::chrono::milliseconds> m_cluster_monitor_interval;
|
||||
config::Count m_health_check_threshold;
|
||||
config::Bool m_dynamic_node_detection;
|
||||
config::Integer m_health_check_port;
|
||||
};
|
||||
|
||||
~ClustrixMonitor();
|
||||
|
@ -233,7 +233,7 @@ private:
|
||||
std::string m_ip;
|
||||
int m_mysql_port {DEFAULT_MYSQL_PORT};
|
||||
int m_health_port {DEFAULT_HEALTH_PORT};
|
||||
int m_health_check_threshold {DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE};
|
||||
int m_health_check_threshold {DEFAULT_HEALTH_CHECK_THRESHOLD};
|
||||
int m_nRunning {0};
|
||||
SERVER* m_pServer {nullptr};
|
||||
MYSQL* m_pCon {nullptr};
|
||||
|
Reference in New Issue
Block a user