MXS-1775 Add disk space threshold to server and monitor

- Instance variable.
- Functions for setting it from configuration file.
This commit is contained in:
Johan Wikman
2018-05-23 11:24:54 +03:00
parent cb8cd4be3d
commit 11c04ff8a8
4 changed files with 83 additions and 0 deletions

View File

@ -137,6 +137,7 @@ MXS_MONITOR* monitor_create(const char *name, const char *module)
mon->parameters = NULL;
mon->server_pending_changes = false;
memset(mon->journal_hash, 0, sizeof(mon->journal_hash));
mon->disk_space_threshold = NULL;
spinlock_init(&mon->lock);
if ((mon->instance = mon->api->createInstance(mon)) == NULL)
@ -187,6 +188,7 @@ monitor_destroy(MXS_MONITOR *mon)
spinlock_release(&monLock);
mon->api->destroyInstance(mon->instance);
mon->state = MONITOR_STATE_FREED;
delete mon->disk_space_threshold;
config_parameter_free(mon->parameters);
monitor_server_free_all(mon->monitored_servers);
MXS_FREE(mon->name);
@ -2508,6 +2510,34 @@ int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, const char* key,
return found;
}
bool monitor_set_disk_space_threshold(MXS_MONITOR *monitor, const char *disk_space_threshold)
{
bool rv = false;
MxsDiskSpaceThreshold dst;
rv = config_parse_disk_space_threshold(&dst, disk_space_threshold);
if (rv)
{
if (!monitor->disk_space_threshold)
{
monitor->disk_space_threshold = new (std::nothrow) MxsDiskSpaceThreshold;
}
if (monitor->disk_space_threshold)
{
monitor->disk_space_threshold->swap(dst);
}
else
{
rv = false;
}
}
return rv;
}
namespace maxscale
{

View File

@ -147,6 +147,7 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
// Log all warnings once
server->warn_ssl_not_enabled = true;
server->disk_space_threshold = NULL;
spinlock_acquire(&server_spin);
server->next = allServers;
allServers = server;
@ -201,6 +202,7 @@ server_free(SERVER *tofreeserver)
dcb_persistent_clean_count(tofreeserver->persistent[i], i, true);
}
}
delete tofreeserver->disk_space_threshold;
MXS_FREE(tofreeserver);
return 1;
}
@ -1564,3 +1566,31 @@ json_t* server_list_to_json(const char* host)
return mxs_json_resource(host, MXS_JSON_API_SERVERS, data);
}
bool server_set_disk_space_threshold(SERVER *server, const char *disk_space_threshold)
{
bool rv = false;
MxsDiskSpaceThreshold dst;
rv = config_parse_disk_space_threshold(&dst, disk_space_threshold);
if (rv)
{
if (!server->disk_space_threshold)
{
server->disk_space_threshold = new (std::nothrow) MxsDiskSpaceThreshold;
}
if (server->disk_space_threshold)
{
server->disk_space_threshold->swap(dst);
}
else
{
rv = false;
}
}
return rv;
}