added first counters

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent c2b8ccdec4
commit 4d55315487
  1. 5
      src/actions.c
  2. 1
      src/connection.c
  3. 31
      src/plugin_core.c
  4. 2
      src/server.c
  5. 15
      src/server.h
  6. 19
      src/utils.c
  7. 3
      src/utils.h

@ -20,7 +20,7 @@ void action_release(server *srv, action *a) {
case ACTION_TSETTING:
release_option(srv, &a->value.setting);
break;
case ACTION_TFUNCTION:
case ACTION_TFUNCTION:
if (a->value.function.free) {
a->value.function.free(srv, a->value.function.param);
}
@ -155,6 +155,9 @@ action_result action_execute(server *srv, connection *con) {
action_stack_pop(srv, as);
continue;
}
srv->stats.actions_executed++;
switch (a->type) {
case ACTION_TSETTING:
con->options[a->value.setting.ndx] = a->value.setting.value;

@ -299,6 +299,7 @@ void connection_state_machine(server *srv, connection *con) {
}
connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST_HEADER);
request_validate_header(srv, con);
srv->stats.requests++;
break;
case CON_STATE_HANDLE_REQUEST_HEADER:

@ -1,6 +1,7 @@
#include "base.h"
#include "plugin_core.h"
#include "utils.h"
static action* core_list(server *srv, plugin* p, option *opt) {
action *a;
@ -176,6 +177,10 @@ static action_result core_handle_test(server *srv, connection *con, gpointer par
GHashTableIter iter;
gpointer k, v;
GList *hv;
GString *str;
guint64 uptime;
guint64 avg1, avg2, avg3;
gchar suffix1[2] = {0,0}, suffix2[2] = {0,0}, suffix3[2] = {0,0};
UNUSED(param);
if (con->state != CON_STATE_HANDLE_REQUEST_HEADER) return ACTION_GO_ON;
@ -187,6 +192,32 @@ static action_result core_handle_test(server *srv, connection *con, gpointer par
chunkqueue_append_mem(con->out, GSTR_LEN(con->request.uri.path));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\nquery: "));
chunkqueue_append_mem(con->out, GSTR_LEN(con->request.uri.query));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n\r\nactions executed: "));
uptime = (guint64)(ev_now(srv->loop) - srv->started);
if (uptime == 0)
uptime = 1;
avg1 = srv->stats.actions_executed;
suffix1[0] = counter_format(&avg1, 1000);
avg2 = srv->stats.actions_executed / uptime;
suffix2[0] = counter_format(&avg2, 1000);
avg3 = srv->stats.actions_executed / srv->stats.requests;
suffix3[0] = counter_format(&avg3, 1000);
str = g_string_sized_new(0);
g_string_printf(str,
"%"G_GUINT64_FORMAT"%s (%"G_GUINT64_FORMAT"%s/s, %"G_GUINT64_FORMAT"%s/req)",
avg1, suffix1, avg2, suffix2, avg3, suffix3
);
chunkqueue_append_string(con->out, str);
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\nrequests: "));
avg1 = srv->stats.requests;
suffix1[0] = counter_format(&avg1, 1000);
avg2 = srv->stats.requests / uptime;
suffix2[0] = counter_format(&avg2, 1000);
str = g_string_sized_new(0);
g_string_printf(str, "%"G_GUINT64_FORMAT"%s (%"G_GUINT64_FORMAT"%s/s)", avg1, suffix1, avg2, suffix2);
chunkqueue_append_string(con->out, str);
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n\r\n--- headers ---\r\n"));
g_hash_table_iter_init(&iter, con->request.headers->table);
while (g_hash_table_iter_next(&iter, &k, &v)) {

@ -297,6 +297,8 @@ void server_start(server *srv) {
ev_io_start(srv->loop, &sock->watcher);
}
srv->started = ev_now(srv->loop);
log_thread_start(srv);
ev_loop(srv->loop, 0);

@ -21,6 +21,18 @@ struct server_socket {
ev_io watcher;
};
struct statistics_t;
typedef struct statistics_t statistics_t;
struct statistics_t {
guint64 bytes_out; /** bytes transfered, outgoing */
guint64 bytes_int; /** bytes transfered, incoming */
guint64 requests; /** processed requests */
guint64 actions_executed; /** actions executed */
};
struct server {
guint32 magic; /** server magic version, check against LIGHTTPD_SERVER_MAGIC in plugins */
server_state state;
@ -60,6 +72,9 @@ struct server {
GAsyncQueue *log_queue;
GThread *log_thread;
GMutex *log_mutex; /* manage access for the logs hashtable */
ev_tstamp started;
statistics_t stats;
};

@ -236,3 +236,22 @@ gchar *http_status_string(guint status_code) {
default: return "unknown status";
}
}
gchar counter_format(guint64 *count, guint factor) {
gchar suffix = 0;
if (*count > factor) { *count /= factor; suffix = 'k';
if (*count > factor) { *count /= factor; suffix = 'm';
if (*count > factor) { *count /= factor; suffix = 'g';
if (*count > factor) { *count /= factor; suffix = 't';
if (*count > factor) { *count /= factor; suffix = 'p';
if (*count > factor) { *count /= factor; suffix = 'e'; }
}
}
}
}
}
return suffix;
}

@ -19,4 +19,7 @@ LI_API void path_simplify(GString *path);
LI_API gchar *http_status_string(guint status_code);
/* */
LI_API gchar counter_format(guint64 *count, guint factor);
#endif

Loading…
Cancel
Save