MXS-1220: Implement /maxscale/logs resource

The /maxscale/logs resource exposes information about the state of logging
in MaxScale.
This commit is contained in:
Markus Mäkelä 2017-05-05 11:59:46 +03:00
parent d4212b9c78
commit 1cb2783106
3 changed files with 33 additions and 5 deletions

View File

@ -13,11 +13,14 @@
*/
#include <maxscale/cdefs.h>
#include <assert.h>
#include <stdbool.h>
#include <syslog.h>
#include <unistd.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS
/**
@ -105,6 +108,7 @@ void mxs_log_set_augmentation(int bits);
void mxs_log_set_throttling(const MXS_LOG_THROTTLING* throttling);
void mxs_log_get_throttling(MXS_LOG_THROTTLING* throttling);
json_t* mxs_logs_to_json(const char* host);
static inline bool mxs_log_priority_is_enabled(int priority)
{

View File

@ -11,10 +11,10 @@
* Public License.
*/
#include <maxscale/log_manager.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
@ -23,14 +23,17 @@
#include <stdarg.h>
#include <errno.h>
#include <syslog.h>
#include <maxscale/atomic.h>
#include <maxscale/platform.h>
#include <maxscale/atomic.h>
#include <maxscale/config.h>
#include <maxscale/platform.h>
#include <maxscale/hashtable.h>
#include <maxscale/json_api.h>
#include <maxscale/spinlock.h>
#include <maxscale/debug.h>
#include <maxscale/alloc.h>
#include <maxscale/utils.h>
#include "maxscale/mlist.h"
#define MAX_PREFIXLEN 250
@ -3013,3 +3016,25 @@ const char* mxs_strerror(int error)
return strerror_r(error, errbuf, sizeof(errbuf));
}
json_t* mxs_logs_to_json(const char* host)
{
json_t* attr = json_object();
json_object_set_new(attr, "highprecision", json_boolean(log_config.do_highprecision));
json_object_set_new(attr, "maxlog", json_boolean(log_config.do_maxlog));
json_object_set_new(attr, "syslog", json_boolean(log_config.do_syslog));
json_t* throttling = json_object();
json_object_set_new(throttling, "count", json_integer(log_config.throttling.count));
json_object_set_new(throttling, "suppress_ms", json_integer(log_config.throttling.suppress_ms));
json_object_set_new(throttling, "window_ms", json_integer(log_config.throttling.window_ms));
json_object_set_new(attr, "throttling", throttling);
json_t* data = json_object();
json_object_set_new(data, CN_ATTRIBUTES, attr);
json_object_set_new(data, CN_ID, json_string("logs"));
json_object_set_new(data, CN_TYPE, json_string("logs"));
return mxs_json_resource(host, MXS_JSON_API_LOGS, data);
}

View File

@ -359,8 +359,7 @@ HttpResponse cb_maxscale(const HttpRequest& request)
HttpResponse cb_logs(const HttpRequest& request)
{
// TODO: Show logs
return HttpResponse(MHD_HTTP_OK, mxs_json_resource(request.host(), MXS_JSON_API_LOGS, json_null()));
return HttpResponse(MHD_HTTP_OK, mxs_logs_to_json(request.host()));
}
HttpResponse cb_flush(const HttpRequest& request)