Move remaining monitor status print functions inside class
This commit is contained in:
@ -78,8 +78,6 @@ extern const char CN_MONITOR_INTERVAL[];
|
||||
extern const char CN_SCRIPT[];
|
||||
extern const char CN_SCRIPT_TIMEOUT[];
|
||||
|
||||
json_t* monitor_json_data(const mxs::Monitor* monitor, const char* host);
|
||||
|
||||
/**
|
||||
* The monitor API version number. Any change to the monitor module API
|
||||
* must change these versions using the rules defined in modinfo.h
|
||||
@ -358,6 +356,8 @@ public:
|
||||
*/
|
||||
void deactivate();
|
||||
|
||||
json_t* to_json(const char* host) const;
|
||||
|
||||
/**
|
||||
* Write diagnostic information to a DCB.
|
||||
*
|
||||
@ -585,6 +585,7 @@ private:
|
||||
|
||||
FILE* open_data_file(Monitor* monitor, char* path);
|
||||
int get_data_file_path(char* path) const;
|
||||
json_t* parameters_to_json() const;
|
||||
|
||||
mxb::StopWatch m_disk_space_checked; /**< When was disk space checked the last time */
|
||||
std::atomic_bool m_status_change_pending {false}; /**< Set when admin requests a status change. */
|
||||
|
||||
@ -412,19 +412,6 @@ bool process_data_file(Monitor* monitor, MonitorServer** 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);
|
||||
auto mon_config = monitor->parameters();
|
||||
config_add_module_params_json(&mon_config,
|
||||
{CN_TYPE, CN_MODULE, CN_SERVERS},
|
||||
config_monitor_params,
|
||||
mod->parameters,
|
||||
rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool check_disk_space_exhausted(MonitorServer* pMs,
|
||||
const std::string& path,
|
||||
const maxscale::disk::SizesAndName& san,
|
||||
@ -456,50 +443,6 @@ const char WRN_REQUEST_OVERWRITTEN[] =
|
||||
"Previous maintenance request was not yet read by the monitor and was overwritten.";
|
||||
}
|
||||
|
||||
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->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->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 (MonitorServer* 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->name()));
|
||||
return rval;
|
||||
}
|
||||
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
@ -698,6 +641,65 @@ void Monitor::show(DCB* dcb)
|
||||
dcb_printf(dcb, "\n");
|
||||
}
|
||||
|
||||
json_t* Monitor::to_json(const char* host) const
|
||||
{
|
||||
// This function mostly reads settings-type data, which is only written to by the admin thread,
|
||||
// The rest is safe to read without mutexes.
|
||||
mxb_assert(Monitor::is_admin_thread());
|
||||
json_t* rval = json_object();
|
||||
json_t* attr = json_object();
|
||||
json_t* rel = json_object();
|
||||
|
||||
auto my_name = name();
|
||||
json_object_set_new(rval, CN_ID, json_string(my_name));
|
||||
json_object_set_new(rval, CN_TYPE, json_string(CN_MONITORS));
|
||||
|
||||
json_object_set_new(attr, CN_MODULE, json_string(m_module.c_str()));
|
||||
auto my_state = state();
|
||||
json_object_set_new(attr, CN_STATE, json_string(monitor_state_to_string(my_state)));
|
||||
json_object_set_new(attr, CN_TICKS, json_integer(ticks()));
|
||||
|
||||
/** Monitor parameters */
|
||||
json_object_set_new(attr, CN_PARAMETERS, parameters_to_json());
|
||||
|
||||
if (my_state == MONITOR_STATE_RUNNING)
|
||||
{
|
||||
json_t* diag = diagnostics_json();
|
||||
if (diag)
|
||||
{
|
||||
json_object_set_new(attr, CN_MONITOR_DIAGNOSTICS, diag);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_servers.empty())
|
||||
{
|
||||
json_t* mon_rel = mxs_json_relationship(host, MXS_JSON_API_SERVERS);
|
||||
for (MonitorServer* db : 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, my_name));
|
||||
return rval;
|
||||
}
|
||||
|
||||
json_t* Monitor::parameters_to_json() const
|
||||
{
|
||||
json_t* rval = json_object();
|
||||
const MXS_MODULE* mod = get_module(m_module.c_str(), MODULE_MONITOR);
|
||||
auto my_config = parameters();
|
||||
config_add_module_params_json(&my_config,
|
||||
{CN_TYPE, CN_MODULE, CN_SERVERS},
|
||||
config_monitor_params,
|
||||
mod->parameters,
|
||||
rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Monitor::test_permissions(const string& query)
|
||||
{
|
||||
auto monitor = this;
|
||||
|
||||
@ -464,14 +464,14 @@ 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));
|
||||
return mxs_json_resource(host, self.c_str(), monitor->to_json(host));
|
||||
}
|
||||
|
||||
json_t* MonitorManager::monitor_list_to_json(const char* host)
|
||||
{
|
||||
json_t* rval = json_array();
|
||||
this_unit.foreach_monitor([rval, host](Monitor* mon) {
|
||||
json_t* json = monitor_json_data(mon, host);
|
||||
json_t* json = mon->to_json(host);
|
||||
if (json)
|
||||
{
|
||||
json_array_append_new(rval, json);
|
||||
|
||||
Reference in New Issue
Block a user