lighttpd 1.4.x https://www.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

985 lines
30 KiB

#include "first.h"
#include "base.h"
#include "connections.h"
#include "response.h"
#include "connections.h"
#include "fdevent.h"
#include "log.h"
#include "plugin.h"
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <stdio.h>
typedef struct {
buffer *config_url;
buffer *status_url;
buffer *statistics_url;
int sort;
} plugin_config;
typedef struct {
PLUGIN_DATA;
double traffic_out;
double requests;
double mod_5s_traffic_out[5];
double mod_5s_requests[5];
size_t mod_5s_ndx;
double rel_traffic_out;
double rel_requests;
double abs_traffic_out;
double abs_requests;
double bytes_written;
buffer *module_list;
plugin_config **config_storage;
plugin_config conf;
} plugin_data;
INIT_FUNC(mod_status_init) {
plugin_data *p;
size_t i;
p = calloc(1, sizeof(*p));
p->traffic_out = p->requests = 0;
p->rel_traffic_out = p->rel_requests = 0;
p->abs_traffic_out = p->abs_requests = 0;
p->bytes_written = 0;
p->module_list = buffer_init();
for (i = 0; i < 5; i++) {
p->mod_5s_traffic_out[i] = p->mod_5s_requests[i] = 0;
}
return p;
}
FREE_FUNC(mod_status_free) {
plugin_data *p = p_d;
UNUSED(srv);
if (!p) return HANDLER_GO_ON;
buffer_free(p->module_list);
if (p->config_storage) {
size_t i;
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s = p->config_storage[i];
if (NULL == s) continue;
buffer_free(s->status_url);
buffer_free(s->statistics_url);
buffer_free(s->config_url);
free(s);
}
free(p->config_storage);
}
free(p);
return HANDLER_GO_ON;
}
SETDEFAULTS_FUNC(mod_status_set_defaults) {
plugin_data *p = p_d;
size_t i;
config_values_t cv[] = {
{ "status.status-url", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
{ "status.config-url", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
{ "status.enable-sort", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
{ "status.statistics-url", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
};
if (!p) return HANDLER_ERROR;
p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *));
for (i = 0; i < srv->config_context->used; i++) {
data_config const* config = (data_config const*)srv->config_context->data[i];
plugin_config *s;
s = calloc(1, sizeof(plugin_config));
s->config_url = buffer_init();
s->status_url = buffer_init();
s->sort = 1;
s->statistics_url = buffer_init();
cv[0].destination = s->status_url;
cv[1].destination = s->config_url;
cv[2].destination = &(s->sort);
cv[3].destination = s->statistics_url;
p->config_storage[i] = s;
if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) {
return HANDLER_ERROR;
}
}
return HANDLER_GO_ON;
}
static int mod_status_row_append(buffer *b, const char *key, const char *value) {
buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <td><b>"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("</b></td>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <td>"));
buffer_append_string(b, value);
buffer_append_string_len(b, CONST_STR_LEN("</td>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
return 0;
}
static int mod_status_header_append(buffer *b, const char *key) {
buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <th colspan=\"2\">"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
return 0;
}
static int mod_status_header_append_sort(buffer *b, void *p_d, const char* key) {
plugin_data *p = p_d;
if (p->conf.sort) {
buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\"><a href=\"#\" class=\"sortheader\" onclick=\"resort(this);return false;\">"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("<span class=\"sortarrow\">:</span></a></th>\n"));
} else {
buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\">"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
}
return 0;
}
static int mod_status_get_multiplier(double *avg, char *multiplier, int size) {
*multiplier = ' ';
if (*avg > size) { *avg /= size; *multiplier = 'k'; }
if (*avg > size) { *avg /= size; *multiplier = 'M'; }
if (*avg > size) { *avg /= size; *multiplier = 'G'; }
if (*avg > size) { *avg /= size; *multiplier = 'T'; }
if (*avg > size) { *avg /= size; *multiplier = 'P'; }
if (*avg > size) { *avg /= size; *multiplier = 'E'; }
if (*avg > size) { *avg /= size; *multiplier = 'Z'; }
if (*avg > size) { *avg /= size; *multiplier = 'Y'; }
return 0;
}
static handler_t mod_status_handle_server_status_html(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = buffer_init();
size_t j;
double avg;
char multiplier = '\0';
char buf[32];
time_t ts;
int days, hours, mins, seconds;
/*(CON_STATE_CLOSE must be last state in enum connection_state_t)*/
int cstates[CON_STATE_CLOSE+3];
memset(cstates, 0, sizeof(cstates));
buffer_copy_string_len(b, CONST_STR_LEN(
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
" <head>\n"
" <title>Status</title>\n"
" <style type=\"text/css\">\n"
" table.status { border: black solid thin; }\n"
" td { white-space: nowrap; }\n"
" td.int { background-color: #f0f0f0; text-align: right }\n"
" td.string { background-color: #f0f0f0; text-align: left }\n"
" th.status { background-color: black; color: white; font-weight: bold; }\n"
" a.sortheader { background-color: black; color: white; font-weight: bold; text-decoration: none; display: block; }\n"
" span.sortarrow { color: white; text-decoration: none; }\n"
" </style>\n"));
if (!buffer_string_is_empty(con->uri.query) && 0 == memcmp(con->uri.query->ptr, CONST_STR_LEN("refresh="))) {
/* Note: Refresh is an historical, but non-standard HTTP header
* References (meta http-equiv="refresh" use is deprecated):
* https://www.w3.org/TR/WCAG10-HTML-TECHS/#meta-element
* https://www.w3.org/TR/WCAG10-CORE-TECHS/#auto-page-refresh
* https://www.w3.org/QA/Tips/reback
*/
const long refresh = strtol(con->uri.query->ptr+sizeof("refresh=")-1, NULL, 10);
if (refresh > 0) {
buffer_append_string_len(b, CONST_STR_LEN("<meta http-equiv=\"refresh\" content=\""));
buffer_append_int(b, refresh < 604800 ? refresh : 604800);
buffer_append_string_len(b, CONST_STR_LEN("\">\n"));
}
}
if (p->conf.sort) {
buffer_append_string_len(b, CONST_STR_LEN(
"<script type=\"text/javascript\">\n"
"// <!--\n"
"var sort_column;\n"
"var prev_span = null;\n"
"function get_inner_text(el) {\n"
" if((typeof el == 'string')||(typeof el == 'undefined'))\n"
" return el;\n"
" if(el.innerText)\n"
" return el.innerText;\n"
" else {\n"
" var str = \"\";\n"
" var cs = el.childNodes;\n"
" var l = cs.length;\n"
" for (i=0;i<l;i++) {\n"
" if (cs[i].nodeType==1) str += get_inner_text(cs[i]);\n"
" else if (cs[i].nodeType==3) str += cs[i].nodeValue;\n"
" }\n"
" }\n"
" return str;\n"
"}\n"
"function sortfn(a,b) {\n"
" var at = get_inner_text(a.cells[sort_column]);\n"
" var bt = get_inner_text(b.cells[sort_column]);\n"
" if (a.cells[sort_column].className == 'int') {\n"
" return parseInt(at)-parseInt(bt);\n"
" } else {\n"
" aa = at.toLowerCase();\n"
" bb = bt.toLowerCase();\n"
" if (aa==bb) return 0;\n"
" else if (aa<bb) return -1;\n"
" else return 1;\n"
" }\n"
"}\n"
"function resort(lnk) {\n"
" var span = lnk.childNodes[1];\n"
" var table = lnk.parentNode.parentNode.parentNode.parentNode;\n"
" var rows = new Array();\n"
" for (j=1;j<table.rows.length;j++)\n"
" rows[j-1] = table.rows[j];\n"
" sort_column = lnk.parentNode.cellIndex;\n"
" rows.sort(sortfn);\n"
" if (prev_span != null) prev_span.innerHTML = '';\n"
" if (span.getAttribute('sortdir')=='down') {\n"
" span.innerHTML = '&uarr;';\n"
" span.setAttribute('sortdir','up');\n"
" rows.reverse();\n"
" } else {\n"
" span.innerHTML = '&darr;';\n"
" span.setAttribute('sortdir','down');\n"
" }\n"
" for (i=0;i<rows.length;i++)\n"
" table.tBodies[0].appendChild(rows[i]);\n"
" prev_span = span;\n"
"}\n"
"// -->\n"
"</script>\n"));
}
buffer_append_string_len(b, CONST_STR_LEN(
" </head>\n"
" <body>\n"));
/* connection listing */
buffer_append_string_len(b, CONST_STR_LEN("<h1>Server-Status ("));
buffer_append_string_buffer(b, con->conf.server_tag);
buffer_append_string_len(b, CONST_STR_LEN(")</h1>"));
buffer_append_string_len(b, CONST_STR_LEN("<table summary=\"status\" class=\"status\">"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Hostname</td><td class=\"string\">"));
buffer_append_string_buffer(b, con->uri.authority);
buffer_append_string_len(b, CONST_STR_LEN(" ("));
buffer_append_string_buffer(b, con->server_name);
buffer_append_string_len(b, CONST_STR_LEN(")</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Uptime</td><td class=\"string\">"));
ts = srv->cur_ts - srv->startup_ts;
days = ts / (60 * 60 * 24);
ts %= (60 * 60 * 24);
hours = ts / (60 * 60);
ts %= (60 * 60);
mins = ts / (60);
ts %= (60);
seconds = ts;
if (days) {
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, days);
buffer_append_string_len(b, CONST_STR_LEN(" days "));
}
if (hours) {
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, hours);
buffer_append_string_len(b, CONST_STR_LEN(" hours "));
}
if (mins) {
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, mins);
buffer_append_string_len(b, CONST_STR_LEN(" min "));
}
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, seconds);
buffer_append_string_len(b, CONST_STR_LEN(" s"));
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Started at</td><td class=\"string\">"));
ts = srv->startup_ts;
strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", localtime(&ts));
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">absolute (since start)</th></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
avg = p->abs_requests;
mod_status_get_multiplier(&avg, &multiplier, 1000);
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("req</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
avg = p->abs_traffic_out;
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (since start)</th></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
avg = p->abs_requests / (srv->cur_ts - srv->startup_ts);
mod_status_get_multiplier(&avg, &multiplier, 1000);
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
avg = p->abs_traffic_out / (srv->cur_ts - srv->startup_ts);
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (5s sliding average)</th></tr>\n"));
for (j = 0, avg = 0; j < 5; j++) {
avg += p->mod_5s_requests[j];
}
avg /= 5;
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
mod_status_get_multiplier(&avg, &multiplier, 1000);
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
for (j = 0, avg = 0; j < 5; j++) {
avg += p->mod_5s_traffic_out[j];
}
avg /= 5;
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("</table>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<hr />\n<pre>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<b>"));
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, srv->conns->used);
buffer_append_string_len(b, CONST_STR_LEN(" connections</b>\n"));
for (j = 0; j < srv->conns->used; j++) {
connection *c = srv->conns->ptr[j];
const char *state;
if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.orig_uri)) {
state = "k";
++cstates[CON_STATE_CLOSE+2];
} else {
state = connection_get_short_state(c->state);
++cstates[(c->state <= CON_STATE_CLOSE ? c->state : CON_STATE_CLOSE+1)];
}
buffer_append_string_len(b, state, 1);
if (((j + 1) % 50) == 0) {
buffer_append_string_len(b, CONST_STR_LEN("\n"));
}
}
buffer_append_string_len(b, CONST_STR_LEN("\n\n<table>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td style=\"text-align:right\">"));
buffer_append_int(b, cstates[CON_STATE_CLOSE+2]);
buffer_append_string_len(b, CONST_STR_LEN("<td>&nbsp;&nbsp;k = keep-alive</td></tr>\n"));
for (j = 0; j < CON_STATE_CLOSE+2; ++j) {
/*(skip "unknown" state if there are none; there should not be any unknown)*/
if (0 == cstates[j] && j == CON_STATE_CLOSE+1) continue;
buffer_append_string_len(b, CONST_STR_LEN("<tr><td style=\"text-align:right\">"));
buffer_append_int(b, cstates[j]);
buffer_append_string_len(b, CONST_STR_LEN("</td><td>&nbsp;&nbsp;"));
buffer_append_string_len(b, connection_get_short_state(j), 1);
buffer_append_string_len(b, CONST_STR_LEN(" = "));
buffer_append_string(b, connection_get_state(j));
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
}
buffer_append_string_len(b, CONST_STR_LEN("</table>"));
buffer_append_string_len(b, CONST_STR_LEN("\n</pre><hr />\n<h2>Connections</h2>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<table summary=\"status\" class=\"status\">\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr>"));
mod_status_header_append_sort(b, p_d, "Client IP");
mod_status_header_append_sort(b, p_d, "Read");
mod_status_header_append_sort(b, p_d, "Written");
mod_status_header_append_sort(b, p_d, "State");
mod_status_header_append_sort(b, p_d, "Time");
mod_status_header_append_sort(b, p_d, "Host");
mod_status_header_append_sort(b, p_d, "URI");
mod_status_header_append_sort(b, p_d, "File");
buffer_append_string_len(b, CONST_STR_LEN("</tr>\n"));
for (j = 0; j < srv->conns->used; j++) {
connection *c = srv->conns->ptr[j];
buffer_append_string_len(b, CONST_STR_LEN("<tr><td class=\"string\">"));
buffer_append_string_buffer(b, c->dst_addr_buf);
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
if (c->request.content_length) {
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, c->request_content_queue->bytes_in);
buffer_append_string_len(b, CONST_STR_LEN("/"));
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, c->request.content_length);
} else {
buffer_append_string_len(b, CONST_STR_LEN("0/0"));
}
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, c->write_queue->bytes_out);
buffer_append_string_len(b, CONST_STR_LEN("/"));
fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
8 years ago
buffer_append_int(b, c->write_queue->bytes_out + chunkqueue_length(c->write_queue));
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
if (CON_STATE_READ == c->state && !buffer_string_is_empty(c->request.orig_uri)) {
buffer_append_string_len(b, CONST_STR_LEN("keep-alive"));
} else {
buffer_append_string(b, connection_get_state(c->state));
}
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));