diff --git a/include/maxscale/monitor.h b/include/maxscale/monitor.h index 2ffcece32..f65f6d183 100644 --- a/include/maxscale/monitor.h +++ b/include/maxscale/monitor.h @@ -266,6 +266,7 @@ struct mxs_monitor time_t journal_max_age; /**< Maximum age of journal file */ uint32_t script_timeout; /**< Timeout in seconds for the monitor scripts */ uint8_t journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */ + MxsDiskSpaceThreshold* disk_space_threshold; /**< Disk space thresholds */ struct mxs_monitor *next; /**< Next monitor in the linked list */ }; @@ -444,4 +445,14 @@ MXS_MONITORED_SERVER* mon_get_monitored_server(const MXS_MONITOR* mon, SERVER* s int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, const char* key, const MXS_MONITOR* mon, MXS_MONITORED_SERVER*** monitored_array_out); +/** + * @brief Set the disk space threshold of a monitor + * + * @param server The monitor. + * @param disk_space_threshold The disk space threshold as specified in the config file. + * + * @return True, if the provided string is valid and the threshold could be set. + */ +bool monitor_set_disk_space_threshold(MXS_MONITOR *monitor, const char *disk_space_threshold); + MXS_END_DECLS diff --git a/include/maxscale/server.h b/include/maxscale/server.h index 4716fb687..398c18444 100644 --- a/include/maxscale/server.h +++ b/include/maxscale/server.h @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -159,6 +160,7 @@ typedef struct server bool master_err_is_logged; /**< If node failed, this indicates whether it is logged. Only used * by rwsplit. TODO: Move to rwsplit */ bool warn_ssl_not_enabled; /**< SSL not used for an SSL enabled server */ + MxsDiskSpaceThreshold* disk_space_threshold; /**< Disk space thresholds */ #if defined(SS_DEBUG) skygw_chk_t server_chk_tail; #endif @@ -359,6 +361,16 @@ json_t* server_to_json(const SERVER* server, const char* host); */ json_t* server_list_to_json(const char* host); +/** + * @brief Set the disk space threshold of the server + * + * @param server The server. + * @param disk_space_threshold The disk space threshold as specified in the config file. + * + * @return True, if the provided string is valid and the threshold could be set. + */ +bool server_set_disk_space_threshold(SERVER *server, const char *disk_space_threshold); + extern int server_free(SERVER *server); extern SERVER *server_find_by_unique_name(const char *name); extern int server_find_by_unique_names(char **server_names, int size, SERVER*** output); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index d4ffad8cb..2216e4d95 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -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 { diff --git a/server/core/server.cc b/server/core/server.cc index c7b80eabc..4a3a546e8 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -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; +}