dump request vars in stats (if possibile and safe)

This commit is contained in:
Roberto De Ioris
2013-01-21 14:24:42 +01:00
parent 0daff2cfe2
commit dda6bb2a5f
4 changed files with 62 additions and 1 deletions
+12 -1
View File
@@ -1093,7 +1093,18 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
if (uwsgi_stats_keylong_comma(us, "offloaded_requests", (unsigned long long) uc->offloaded_requests))
goto end;
if (uwsgi_stats_keylong(us, "in_request", (unsigned long long) uc->in_request))
if (uwsgi_stats_keylong_comma(us, "in_request", (unsigned long long) uc->in_request))
goto end;
if (uwsgi_stats_key(us, "vars"))
goto end;
if (uwsgi_stats_list_open(us))
goto end;
if (uwsgi_stats_dump_vars(us, uc)) goto end;
if (uwsgi_stats_list_close(us))
goto end;
+47
View File
@@ -13,6 +13,7 @@ struct uwsgi_stats *uwsgi_stats_new(size_t chunk_size) {
us->chunk = chunk_size;
us->size = chunk_size;
us->tabs = 1;
us->dirty = 0;
us->minified = uwsgi.stats_minified;
if (!us->minified) {
us->base[1] = '\n';
@@ -520,3 +521,49 @@ void uwsgi_stats_pusher_file(struct uwsgi_stats_pusher_instance *uspi, char *jso
close(fd);
}
static void stats_dump_var(char *k, uint16_t kl, char *v, uint16_t vl, void *data) {
struct uwsgi_stats *us = (struct uwsgi_stats *) data;
if (us->dirty) return;
uint16_t i;
// replace " with '
for(i=0;i<kl;i++) {
if (k[i] == '"') {
k[i] = '\'';
}
}
for(i=0;i<vl;i++) {
if (v[i] == '"') {
v[i] = '\'';
}
}
char *var = uwsgi_concat3n(k, kl, "=", 1, v,vl);
if (uwsgi_stats_str(us, var)) {
us->dirty = 1;
free(var);
return;
}
free(var);
if (uwsgi_stats_comma(us)) {
us->dirty = 1;
}
return;
}
int uwsgi_stats_dump_vars(struct uwsgi_stats *us, struct uwsgi_core *uc) {
if (!uc->in_request) return 0;
uint16_t pktsize = uc->req.uh.pktsize;
if (!pktsize) return 0;
char *dst = uwsgi.workers[0].cores[0].buffer;
memcpy(dst, uc->buffer, uwsgi.buffer_size);
// ok now check if something changed...
if (!uc->in_request) return 0;
if (uc->req.uh.pktsize != pktsize) return 0;
if (memcmp(dst, uc->buffer, uwsgi.buffer_size)) return 0;
// nothing changed let's dump vars
int ret = uwsgi_hooked_parse(dst, pktsize, stats_dump_var, us);
if (ret) return -1;
if (us->dirty) return -1;
if (uwsgi_stats_str(us, "")) return -1;
return 0;
}
+2
View File
@@ -3345,6 +3345,7 @@ struct uwsgi_stats {
size_t chunk;
size_t size;
int minified;
int dirty;
};
struct uwsgi_stats_pusher_instance;
@@ -3766,6 +3767,7 @@ int uwsgi_proto_base_fix_headers(struct wsgi_request *);
int uwsgi_response_add_content_length(struct wsgi_request *, uint64_t);
const char *uwsgi_http_status_msg(char *, uint16_t *);
int uwsgi_stats_dump_vars(struct uwsgi_stats *, struct uwsgi_core *);
#define uwsgi_response_add_connection_close(x) uwsgi_response_add_header(x, "Connection", 10, "close", 5)
#define uwsgi_response_add_content_type(x, y, z) uwsgi_response_add_header(x, "Content-Type", 12, y, z)
+1
View File
@@ -22,6 +22,7 @@ except:
def after_request_hook():
return
print("request finished")
uwsgi.after_req_hook = after_request_hook