Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add extended stats #893

Merged
merged 8 commits into from Jun 1, 2016
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -239,7 +239,7 @@ SET(LIB_SOURCE_FILES
lib/handler/redirect.c
lib/handler/reproxy.c
lib/handler/status.c
lib/handler/status/errors.c
lib/handler/status/events.c
lib/handler/status/requests.c
lib/handler/configurator/access_log.c
lib/handler/configurator/compress.c
Expand Down
4 changes: 2 additions & 2 deletions lib/handler/status.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "h2o.h"

extern h2o_status_handler_t errors_status_handler;
extern h2o_status_handler_t events_status_handler;
extern h2o_status_handler_t requests_status_handler;

struct st_h2o_status_logger_t {
Expand Down Expand Up @@ -288,5 +288,5 @@ void h2o_status_register(h2o_pathconf_t *conf)
self->super.on_context_dispose = on_context_dispose;
self->super.on_req = on_req;
h2o_config_register_status_handler(conf->global, requests_status_handler);
h2o_config_register_status_handler(conf->global, errors_status_handler);
h2o_config_register_status_handler(conf->global, events_status_handler);
}
70 changes: 35 additions & 35 deletions lib/handler/status/errors.c → lib/handler/status/events.c
Expand Up @@ -23,17 +23,17 @@
#include "h2o.h"
#include <inttypes.h>

struct st_errors_status_ctx_t {
struct st_events_status_ctx_t {
uint64_t emitted_status_errors[H2O_STATUS_ERROR_MAX];
uint64_t h2_protocol_level_errors[H2O_HTTP2_ERROR_MAX];
uint64_t h2_read_closed;
uint64_t h2_write_closed;
};

static void errors_status_per_thread(void *priv, h2o_context_t *ctx)
static void events_status_per_thread(void *priv, h2o_context_t *ctx)
{
size_t i;
struct st_errors_status_ctx_t *esc = priv;
struct st_events_status_ctx_t *esc = priv;
for (i = 0; i < H2O_STATUS_ERROR_MAX; i++) {
esc->emitted_status_errors[i] += ctx->emitted_error_status[i];
}
Expand All @@ -44,19 +44,19 @@ static void errors_status_per_thread(void *priv, h2o_context_t *ctx)
esc->h2_write_closed += ctx->http2.events.write_closed;
}

static void *errors_status_init(void)
static void *events_status_init(void)
{
struct st_errors_status_ctx_t *ret;
struct st_events_status_ctx_t *ret;

ret = h2o_mem_alloc(sizeof(*ret));
memset(ret, 0, sizeof(*ret));

return ret;
}

static h2o_iovec_t errors_status_final(void *priv, h2o_globalconf_t *gconf, h2o_req_t *req)
static h2o_iovec_t events_status_final(void *priv, h2o_globalconf_t *gconf, h2o_req_t *req)
{
struct st_errors_status_ctx_t *esc = priv;
struct st_events_status_ctx_t *esc = priv;
h2o_iovec_t ret;

#define H1_AGG_ERR(status_) \
Expand All @@ -66,29 +66,29 @@ static h2o_iovec_t errors_status_final(void *priv, h2o_globalconf_t *gconf, h2o_
#define BUFSIZE (2*1024)
ret.base = h2o_mem_alloc_pool(&req->pool, BUFSIZE);
ret.len = snprintf(ret.base, BUFSIZE, ",\n"
" \"http1-errors-400\": %" PRIu64 ",\n"
" \"http1-errors-403\": %" PRIu64 ",\n"
" \"http1-errors-404\": %" PRIu64 ",\n"
" \"http1-errors-405\": %" PRIu64 ",\n"
" \"http1-errors-416\": %" PRIu64 ",\n"
" \"http1-errors-417\": %" PRIu64 ",\n"
" \"http1-errors-500\": %" PRIu64 ",\n"
" \"http1-errors-502\": %" PRIu64 ",\n"
" \"http1-errors-503\": %" PRIu64 ",\n"
" \"http2-errors-protocol\": %" PRIu64 ", \n"
" \"http2-errors-internal\": %" PRIu64 ", \n"
" \"http2-errors-flow_control\": %" PRIu64 ", \n"
" \"http2-errors-settings_timeout\": %" PRIu64 ", \n"
" \"http2-errors-stream_closed\": %" PRIu64 ", \n"
" \"http2-errors-frame_size\": %" PRIu64 ", \n"
" \"http2-errors-refused_stream\": %" PRIu64 ", \n"
" \"http2-errors-cancel\": %" PRIu64 ", \n"
" \"http2-errors-compression\": %" PRIu64 ", \n"
" \"http2-errors-connect\": %" PRIu64 ", \n"
" \"http2-errors-enhance_your_calm\": %" PRIu64 ", \n"
" \"http2-errors-inadequate_security\": %" PRIu64 ", \n"
" \"http2-read-closed\": %" PRIu64 ", \n"
" \"http2-write-closed\": %" PRIu64 "\n",
" \"http1-errors.400\": %" PRIu64 ",\n"
" \"http1-errors.403\": %" PRIu64 ",\n"
" \"http1-errors.404\": %" PRIu64 ",\n"
" \"http1-errors.405\": %" PRIu64 ",\n"
" \"http1-errors.416\": %" PRIu64 ",\n"
" \"http1-errors.417\": %" PRIu64 ",\n"
" \"http1-errors.500\": %" PRIu64 ",\n"
" \"http1-errors.502\": %" PRIu64 ",\n"
" \"http1-errors.503\": %" PRIu64 ",\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the errors to status-errors, as discussed in #893 (comment).

I believe that is the only change required to getting this merged. Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazuho ah yes, of course. That's fixed in a3b35d1

" \"http2-errors.protocol\": %" PRIu64 ", \n"
" \"http2-errors.internal\": %" PRIu64 ", \n"
" \"http2-errors.flow-control\": %" PRIu64 ", \n"
" \"http2-errors.settings-timeout\": %" PRIu64 ", \n"
" \"http2-errors.stream-closed\": %" PRIu64 ", \n"
" \"http2-errors.frame-size\": %" PRIu64 ", \n"
" \"http2-errors.refused-stream\": %" PRIu64 ", \n"
" \"http2-errors.cancel\": %" PRIu64 ", \n"
" \"http2-errors.compression\": %" PRIu64 ", \n"
" \"http2-errors.connect\": %" PRIu64 ", \n"
" \"http2-errors.enhance-your-calm\": %" PRIu64 ", \n"
" \"http2-errors.inadequate-security\": %" PRIu64 ", \n"
" \"http2.read-closed\": %" PRIu64 ", \n"
" \"http2.write-closed\": %" PRIu64 "\n",
H1_AGG_ERR(400), H1_AGG_ERR(403), H1_AGG_ERR(404),
H1_AGG_ERR(405), H1_AGG_ERR(416), H1_AGG_ERR(417),
H1_AGG_ERR(500), H1_AGG_ERR(502), H1_AGG_ERR(503),
Expand All @@ -104,9 +104,9 @@ static h2o_iovec_t errors_status_final(void *priv, h2o_globalconf_t *gconf, h2o_
#undef H2_AGG_ERR
}

h2o_status_handler_t errors_status_handler = {
{ H2O_STRLIT("errors") },
errors_status_init,
errors_status_per_thread,
errors_status_final,
h2o_status_handler_t events_status_handler = {
{ H2O_STRLIT("events") },
events_status_init,
events_status_per_thread,
events_status_final,
};
8 changes: 4 additions & 4 deletions t/50status.t
Expand Up @@ -36,11 +36,11 @@ hosts:
status: ON
EOT

my $resp = `curl --silent -o /dev/stderr 'http://127.0.0.1:$server->{port}/s/json?show=main,errors' 2>&1 > /dev/null`;
my $resp = `curl --silent -o /dev/stderr 'http://127.0.0.1:$server->{port}/s/json?show=main,events' 2>&1 > /dev/null`;
my $jresp = decode_json("$resp");
is $jresp->{'connections'}, 1, "One connection";
is $jresp->{'requests'}, undef, "Requests not present";
is $jresp->{'http1-errors-404'}, 0, "Internal errors monitoring";
is $jresp->{'http1-errors.404'}, 0, "Internal errors monitoring";
};

subtest "json hander check 404 error counter" => sub {
Expand All @@ -54,11 +54,11 @@ hosts:
status: ON
EOT
my $resp = `curl --silent -o /dev/stderr 'http://127.0.0.1:$server->{port}/beeb98fcf148317be5fe5d763c658bc9ea9c087a' 2>&1 > /dev/null`;
my $resp = `curl --silent -o /dev/stderr 'http://127.0.0.1:$server->{port}/s/json?show=errors' 2>&1 > /dev/null`;
my $resp = `curl --silent -o /dev/stderr 'http://127.0.0.1:$server->{port}/s/json?show=events' 2>&1 > /dev/null`;
my $jresp = decode_json("$resp");
is $jresp->{'connections'}, undef, "Connections not present";
is $jresp->{'requests'}, undef, "Requests not present";
is $jresp->{'http1-errors-404'}, 1, "Found the 404 error";
is $jresp->{'http1-errors.404'}, 1, "Found the 404 error";
};


Expand Down