From bbc450f4eb23751b9d65bf5661c8cc5282648786 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 6 Sep 2017 20:31:36 +0200 Subject: [PATCH] web: add new api "status" to fetch runtime status & statistics of http / websockets server --- lib/api/actions/status.c | 53 ++++++++++++++++++++++++++++++++++++++++ thirdparty/Makefile.inc | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 lib/api/actions/status.c diff --git a/lib/api/actions/status.c b/lib/api/actions/status.c new file mode 100644 index 000000000..6e180f1dc --- /dev/null +++ b/lib/api/actions/status.c @@ -0,0 +1,53 @@ +/** The "stats" API action. + * + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#include + +#include "plugin.h" +#include "node.h" +#include "super_node.h" +#include "utils.h" +#include "stats.h" + +#include "api.h" + +static int api_status(struct api_action *r, json_t *args, json_t **resp, struct api_session *s) +{ + int ret; + struct lws_context *ctx = lws_get_context(s->wsi); + char buf[4096]; + + ret = lws_json_dump_context(ctx, buf, sizeof(buf), 0); + + *resp = json_loads(buf, 0, NULL); + + return ret; +} + +static struct plugin p = { + .name = "status", + .description = "get status and statistics of web server", + .type = PLUGIN_TYPE_API, + .api.cb = api_status +}; + +REGISTER_PLUGIN(&p) diff --git a/thirdparty/Makefile.inc b/thirdparty/Makefile.inc index 825f8c1c3..250619dbb 100644 --- a/thirdparty/Makefile.inc +++ b/thirdparty/Makefile.inc @@ -70,7 +70,7 @@ libconfig-fix: rm -f $(SRCDIR)/thirdparty/libconfig/lib/scanner.[hc] jansson: CMAKE_OPTS += -DJANSSON_BUILD_DOCS=OFF -libwebsockets: CMAKE_OPTS += -DLWS_IPV6=1 -DLWS_WITH_STATIC=0 -DLWS_WITHOUT_TESTAPPS=1 -DLWS_WITH_HTTP2=1 +libwebsockets: CMAKE_OPTS += -DLWS_IPV6=1 -DLWS_WITH_STATIC=0 -DLWS_WITHOUT_TESTAPPS=1 -DLWS_WITH_HTTP2=1 -DLWS_WITH_SERVER_STATUS=1 libzmq: CONFIGURE_OPTS += --with-libsodium --with-pgm --enable-drafts .PHONY: $(DEPS) thirdparty clean-thirdparty install-thirdparty