From: Andy Green Date: Mon, 25 Apr 2016 23:45:45 +0000 (+0800) Subject: server status add getloadavg and lib version and more css X-Git-Tag: upstream/2.0.3~76 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12aeba73c0034766ccc3fa8b3a64afba450f2b4d;p=platform%2Fupstream%2Flibwebsockets.git server status add getloadavg and lib version and more css Signed-off-by: Andy Green --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b244a7..d4efa96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,6 +412,7 @@ CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS) CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF) CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF) CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF) +CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG) if (NOT LWS_HAVE_GETIFADDRS) if (LWS_WITHOUT_BUILTIN_GETIFADDRS) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 468dea6..344258a 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -2464,16 +2464,31 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len) int listening = 0, cgi_count = 0, n; buf += snprintf(buf, end - buf, "{ " + "\"version\":\"%s\",\n" "\"uptime\":\"%ld\",\n" "\"cgi_spawned\":\"%d\",\n" "\"pt_fd_max\":\"%d\",\n" "\"ah_pool_max\":\"%d\",\n" "\"wsi_alive\":\"%d\",\n", + lws_get_library_version(), (unsigned long)(t - context->time_up), context->count_cgi_spawned, context->fd_limit_per_thread, context->max_http_header_pool, context->count_wsi_allocated); +#ifdef LWS_HAVE_GETLOADAVG + { + double d[3]; + int m; + + m = getloadavg(d, 3); + for (n = 0; n < m; n++) { + buf += snprintf(buf, end - buf, + "\"l%d\":\"%.2f\",\n", + n + 1, d[n]); + } + } +#endif buf += snprintf(buf, end - buf, "\"pt\":[\n "); for (n = 0; n < context->count_threads; n++) { diff --git a/lws_config_private.h.in b/lws_config_private.h.in index 2079e90..c58d8b6 100644 --- a/lws_config_private.h.in +++ b/lws_config_private.h.in @@ -102,6 +102,8 @@ /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_ZLIB_H +#cmakedefine LWS_HAVE_GETLOADAVG + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR // We're not using libtool diff --git a/plugins/server-status.html b/plugins/server-status.html index 155ac2c..5a299c8 100644 --- a/plugins/server-status.html +++ b/plugins/server-status.html @@ -8,6 +8,16 @@ text-align:center; color:#000000; } span.mount { font-size:10pt; font: Arial; font-weight:normal; text-align:center; color:#000000; } + span.mountname { font-size:14pt; font: Arial; font-weight:bold; + text-align:center; color:#404010; } + span.n { font-size:12pt; font: Arial; font-weight:normal; + text-align:center; color:#808020; } + span.v { font-size:12pt; font: Arial; font-weight:bold; + text-align:center; color:#202020; } + span.m1 { font-size:12pt; font: Arial; font-weight:bold; + text-align:center; color:#202020; } + span.m2 { font-size:12pt; font: Arial; font-weight:normal; + text-align:center; color:#202020; } .browser { font-size:18pt; font: Arial; font-weight:normal; text-align:center; color:#ffff00; vertical-align:middle; text-align:center; background:#d0b070; padding:12px; -webkit-border-radius:10px; -moz-border-radius:10px; border-radius:10px;} .group2 { vertical-align:middle; text-align:center; @@ -124,6 +134,22 @@ function san(s) return s; } +function humanize(s) +{ + i = parseInt(s); + + if (i > 1000000000) + return (i / 1000000000).toFixed(3) + "G"; + + if (i > 1000000) + return (i / 1000000).toFixed(3) + "M"; + + if (i > 1000) + return (i / 1000).toFixed(3) + "K"; + + return s; +} + var pos = 0; function get_appropriate_ws_url() @@ -170,68 +196,85 @@ function get_appropriate_ws_url() } socket_status.onmessage =function got_packet(msg) { - document.getElementById("conninfo").innerHTML = "
"+msg.data+"
"; + var u; + //document.getElementById("conninfo").innerHTML = "
"+msg.data+"
"; jso = JSON.parse(msg.data); - - s=""; + u = parseInt(san(jso.uptime)); + s = "
" + - "ContextUptime: " + san(jso.uptime) + ", " + - "Listening wsi: " + san(jso.listen_wsi) + ", " + - "Current wsi alive: " + (parseInt(san(jso.wsi_alive)) - - parseInt(san(jso.listen_wsi))) + "
" + - "Current cgi alive: " + san(jso.cgi_alive) + ", " + - "Total CGI spawned: " + san(jso.cgi_spawned) + - "
"; var n; for (n = 0; n < jso.pt.length; n++) { s = s + ""; + s = s + ""; } for (n = 0; n < jso.vhosts.length; n++) { s = s + "";
" + + "Context" + + "Version: " + + san(jso.version) + "
" + + "Uptime: " + + ((u / (24 * 3600)) | 0) + "d " + + (((u % (24 * 3600)) / 3600) | 0) + "h " + + (((u % 3600) / 60) | 0) + "m"; + if (jso.l1) + s = s + ", Load: " + san(jso.l1) + " "; + if (jso.l2) + s = s + san(jso.l2) + " "; + if (jso.l3) + s = s + san(jso.l3); + if (jso.l1) + s =s + ""; + s = s + + "
" + + "Listening wsi: " + san(jso.listen_wsi) + ", " + + "Current wsi alive: " + (parseInt(san(jso.wsi_alive)) - + parseInt(san(jso.listen_wsi))) + "
" + + "Current cgi alive: " + san(jso.cgi_alive) + ", " + + "Total CGI spawned: " + san(jso.cgi_spawned) + + "
service thread " + (n + 1) + "" + - "fds: " + san(jso.pt[n].fds_count) + " / " + - san(jso.pt_fd_max) + ", "; - s = s + "ah pool: " + san(jso.pt[n].ah_pool_inuse) + " / " + - san(jso.ah_pool_max) + ", " + - "ah waiting list: " + san(jso.pt[n].ah_wait_list); + "fds: " + san(jso.pt[n].fds_count) + " / " + + san(jso.pt_fd_max) + ", "; + s = s + "ah pool: " + san(jso.pt[n].ah_pool_inuse) + " / " + + san(jso.ah_pool_max) + ", " + + "ah waiting list: " + san(jso.pt[n].ah_wait_list); - s = s + "
vhost " + (n + 1) + - ""; + ""; if (jso.vhosts[n].use_ssl == '1') s = s + "https://"; else s = s + "http://"; s = s + san(jso.vhosts[n].name) + ":" + - san(jso.vhosts[n].port) + ""; + san(jso.vhosts[n].port) + ""; if (jso.vhosts[n].sts == '1') s = s + " (STS)"; s = s +"
" + - "rx " + san(jso.vhosts[n].rx) + ", " + - "tx " + san(jso.vhosts[n].tx) + "
" + - "total connections " + san(jso.vhosts[n].conn) + ", " + - "total http transactions " + san(jso.vhosts[n].trans) + "
" + - "Upgrades to ws: " + san(jso.vhosts[n].ws_upg) + ", " + - "to http/2: " + san(jso.vhosts[n].http2_upg) + "
" + - ""; + "rx:" + humanize(san(jso.vhosts[n].rx)) + "B, " + + "tx" + humanize(san(jso.vhosts[n].tx)) + "B
" + + "total connections" + san(jso.vhosts[n].conn) + ", " + + "total http transactions" + san(jso.vhosts[n].trans) + "
" + + "Upgrades to ws:" + san(jso.vhosts[n].ws_upg) + ", " + + "to http/2:" + san(jso.vhosts[n].http2_upg) + "
" + + "
MountpointOriginCache Policy
"; var m; for (m = 0; m < jso.vhosts[n].mounts.length; m++) { s = s + "" + s = s + "" } s = s + "
MountpointOriginCache Policy
"; - s = s + san(jso.vhosts[n].mounts[m].mountpoint) + - "" + + s = s + "" + san(jso.vhosts[n].mounts[m].mountpoint) + + "" + san(jso.vhosts[n].mounts[m].origin) + - ""; + ""; if (parseInt(san(jso.vhosts[n].mounts[m].cache_max_age))) - s = s + "max-age: " + + s = s + "max-age: " + san(jso.vhosts[n].mounts[m].cache_max_age) + - ", reuse: " + + ", reuse: " + san(jso.vhosts[n].mounts[m].cache_reuse) + - ", reval: " + + ", reval: " + san(jso.vhosts[n].mounts[m].cache_revalidate) + - ", inter: " + + ", inter: " + san(jso.vhosts[n].mounts[m].cache_intermediaries); - s = s + "
"; s = s + "