From b4400d0085d208d21681de150ee13e35203dabf1 Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Sun, 26 Jun 2005 13:28:15 +0000 Subject: [PATCH] - added ?auto handling from Matthijs van der Klip - divide by 1024 only if we are about 10240 - divide non-byte counters by 1000 and not 1024 git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@408 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/mod_status.c | 118 +++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 40 deletions(-) diff --git a/src/mod_status.c b/src/mod_status.c index c6d359ec..34955895 100644 --- a/src/mod_status.c +++ b/src/mod_status.c @@ -154,7 +154,7 @@ static int mod_status_header_append(buffer *b, const char *key) { return 0; } -static handler_t mod_status_handle_server_status(server *srv, connection *con, void *p_d) { +static handler_t mod_status_handle_server_status_html(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; buffer *b; size_t j; @@ -166,7 +166,7 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v int days, hours, mins, seconds; b = chunkqueue_get_append_buffer(con->write_queue); - + BUFFER_COPY_STRING_CONST(b, "\n" "Requests"); avg = p->abs_requests; multiplier = '\0'; - if (avg > 1000) { avg /= 1000; multiplier = 'k'; } - if (avg > 1000) { avg /= 1000; multiplier = 'M'; } - if (avg > 1000) { avg /= 1000; multiplier = 'G'; } - if (avg > 1000) { avg /= 1000; multiplier = 'T'; } - if (avg > 1000) { avg /= 1000; multiplier = 'P'; } - if (avg > 1000) { avg /= 1000; multiplier = 'E'; } - if (avg > 1000) { avg /= 1000; multiplier = 'Z'; } - if (avg > 1000) { avg /= 1000; multiplier = 'Y'; } + if (avg > 10000) { avg /= 1000; multiplier = 'k'; } + if (avg > 10000) { avg /= 1000; multiplier = 'M'; } + if (avg > 10000) { avg /= 1000; multiplier = 'G'; } + if (avg > 10000) { avg /= 1000; multiplier = 'T'; } + if (avg > 10000) { avg /= 1000; multiplier = 'P'; } + if (avg > 10000) { avg /= 1000; multiplier = 'E'; } + if (avg > 10000) { avg /= 1000; multiplier = 'Z'; } + if (avg > 10000) { avg /= 1000; multiplier = 'Y'; } buffer_append_long(b, avg); BUFFER_APPEND_STRING_CONST(b, " "); if (multiplier) buffer_append_string_len(b, &multiplier, 1); @@ -262,16 +262,16 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v BUFFER_APPEND_STRING_CONST(b, "Traffic"); avg = p->abs_traffic_out; multiplier = '\0'; - - if (avg > 1024) { avg /= 1024; multiplier = 'k'; } - if (avg > 1024) { avg /= 1024; multiplier = 'M'; } - if (avg > 1024) { avg /= 1024; multiplier = 'G'; } - if (avg > 1024) { avg /= 1024; multiplier = 'T'; } - if (avg > 1024) { avg /= 1024; multiplier = 'P'; } - if (avg > 1024) { avg /= 1024; multiplier = 'E'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Z'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Y'; } - + + if (avg > 10240) { avg /= 1024; multiplier = 'k'; } + if (avg > 10240) { avg /= 1024; multiplier = 'M'; } + if (avg > 10240) { avg /= 1024; multiplier = 'G'; } + if (avg > 10240) { avg /= 1024; multiplier = 'T'; } + if (avg > 10240) { avg /= 1024; multiplier = 'P'; } + if (avg > 10240) { avg /= 1024; multiplier = 'E'; } + if (avg > 10240) { avg /= 1024; multiplier = 'Z'; } + if (avg > 10240) { avg /= 1024; multiplier = 'Y'; } + buffer_append_long(b, avg); BUFFER_APPEND_STRING_CONST(b, " "); if (multiplier) buffer_append_string_len(b, &multiplier, 1); @@ -287,16 +287,16 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v BUFFER_APPEND_STRING_CONST(b, "Requests"); multiplier = '\0'; - - if (avg > 1024) { avg /= 1024; multiplier = 'k'; } - if (avg > 1024) { avg /= 1024; multiplier = 'M'; } - if (avg > 1024) { avg /= 1024; multiplier = 'G'; } - if (avg > 1024) { avg /= 1024; multiplier = 'T'; } - if (avg > 1024) { avg /= 1024; multiplier = 'P'; } - if (avg > 1024) { avg /= 1024; multiplier = 'E'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Z'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Y'; } - + + if (avg > 10000) { avg /= 1000; multiplier = 'k'; } + if (avg > 10000) { avg /= 1000; multiplier = 'M'; } + if (avg > 10000) { avg /= 1000; multiplier = 'G'; } + if (avg > 10000) { avg /= 1000; multiplier = 'T'; } + if (avg > 10000) { avg /= 1000; multiplier = 'P'; } + if (avg > 10000) { avg /= 1000; multiplier = 'E'; } + if (avg > 10000) { avg /= 1000; multiplier = 'Z'; } + if (avg > 10000) { avg /= 1000; multiplier = 'Y'; } + buffer_append_long(b, avg); BUFFER_APPEND_STRING_CONST(b, " "); if (multiplier) buffer_append_string_len(b, &multiplier, 1); @@ -311,16 +311,16 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v BUFFER_APPEND_STRING_CONST(b, "Traffic"); multiplier = '\0'; - - if (avg > 1024) { avg /= 1024; multiplier = 'k'; } - if (avg > 1024) { avg /= 1024; multiplier = 'M'; } - if (avg > 1024) { avg /= 1024; multiplier = 'G'; } - if (avg > 1024) { avg /= 1024; multiplier = 'T'; } - if (avg > 1024) { avg /= 1024; multiplier = 'P'; } - if (avg > 1024) { avg /= 1024; multiplier = 'E'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Z'; } - if (avg > 1024) { avg /= 1024; multiplier = 'Y'; } - + + if (avg > 10240) { avg /= 1024; multiplier = 'k'; } + if (avg > 10240) { avg /= 1024; multiplier = 'M'; } + if (avg > 10240) { avg /= 1024; multiplier = 'G'; } + if (avg > 10240) { avg /= 1024; multiplier = 'T'; } + if (avg > 10240) { avg /= 1024; multiplier = 'P'; } + if (avg > 10240) { avg /= 1024; multiplier = 'E'; } + if (avg > 10240) { avg /= 1024; multiplier = 'Z'; } + if (avg > 10240) { avg /= 1024; multiplier = 'Y'; } + buffer_append_long(b, avg); BUFFER_APPEND_STRING_CONST(b, " "); if (multiplier) buffer_append_string_len(b, &multiplier, 1); @@ -422,12 +422,50 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); + return 0; +} + + +static handler_t mod_status_handle_server_status_text(server *srv, connection *con, void *p_d) { + plugin_data *p = p_d; + buffer *b; + double avg; + + b = chunkqueue_get_append_buffer(con->write_queue); + + /* output total number of requests */ + BUFFER_APPEND_STRING_CONST(b, "Total Accesses: "); + avg = p->abs_requests; + buffer_append_long(b, avg); + BUFFER_APPEND_STRING_CONST(b, "\n"); + + /* output total traffic out in kbytes */ + BUFFER_APPEND_STRING_CONST(b, "Total kBytes: "); + avg = p->abs_traffic_out / 1024; + buffer_append_long(b, avg); + BUFFER_APPEND_STRING_CONST(b, "\n"); + + /* set text/plain output */ + response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain")); + + return 0; +} + +static handler_t mod_status_handle_server_status(server *srv, connection *con, void *p_d) { + + if (buffer_is_equal_string(con->uri.query, CONST_STR_LEN("auto"))) { + mod_status_handle_server_status_text(srv, con, p_d); + } else { + mod_status_handle_server_status_html(srv, con, p_d); + } + con->http_status = 200; con->file_finished = 1; return HANDLER_FINISHED; } + static handler_t mod_status_handle_server_config(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; buffer *b, *m = p->module_list;