allows exported json stats in http format

This commit is contained in:
Roberto De Ioris
2012-10-30 08:45:32 +01:00
parent 929a919c9d
commit 9342acc500
6 changed files with 42 additions and 0 deletions
+7
View File
@@ -1129,6 +1129,13 @@ void emperor_send_stats(int fd) {
return;
}
if (uwsgi.stats_http) {
if (uwsgi_send_http_stats(client_fd)) {
close(client_fd);
return;
}
}
struct uwsgi_stats *us = uwsgi_stats_new(8192);
if (uwsgi_stats_keyval_comma(us, "version", UWSGI_VERSION))
+7
View File
@@ -778,6 +778,13 @@ void uwsgi_send_stats(int fd) {
return;
}
if (uwsgi.stats_http) {
if (uwsgi_send_http_stats(client_fd)) {
close(client_fd);
return;
}
}
struct uwsgi_stats *us = uwsgi_stats_new(8192);
if (uwsgi_stats_keyval_comma(us, "version", UWSGI_VERSION))
+18
View File
@@ -4891,3 +4891,21 @@ int uwsgi_kvlist_parse(char *src, size_t len, char list_separator, char kv_separ
free(buf);
return 0;
}
int uwsgi_send_http_stats(int fd) {
struct uwsgi_buffer *ub = uwsgi_buffer_new(uwsgi.page_size);
if (!ub) return -1;
if (uwsgi_buffer_append(ub, "HTTP/1.0 200 OK\r\n", 17)) goto error;
if (uwsgi_buffer_append(ub, "Connection: close\r\n", 19)) goto error;
if (uwsgi_buffer_append(ub, "Content-Type: application/json\r\n", 32)) goto error;
if (uwsgi_buffer_append(ub, "\r\n", 2)) goto error;
if (uwsgi_buffer_send(ub, fd)) goto error;
uwsgi_buffer_destroy(ub);
return 0;
error:
uwsgi_buffer_destroy(ub);
return -1;
}
+1
View File
@@ -305,6 +305,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
#endif
{"stats", required_argument, 0, "enable the stats server on the specified address", uwsgi_opt_set_str, &uwsgi.stats, UWSGI_OPT_MASTER},
{"stats-server", required_argument, 0, "enable the stats server on the specified address", uwsgi_opt_set_str, &uwsgi.stats, UWSGI_OPT_MASTER},
{"stats-http", no_argument, 0, "prefix stats server json output with http headers", uwsgi_opt_true, &uwsgi.stats_http, UWSGI_OPT_MASTER},
#ifdef UWSGI_MULTICAST
{"multicast", required_argument, 0, "subscribe to specified multicast group", uwsgi_opt_set_str, &uwsgi.multicast_group, UWSGI_OPT_MASTER},
{"multicast-ttl", required_argument, 0, "set multicast ttl", uwsgi_opt_set_int, &uwsgi.multicast_ttl, 0},
+7
View File
@@ -933,6 +933,13 @@ void corerouter_send_stats(struct uwsgi_corerouter *ucr) {
return;
}
if (uwsgi.stats_http) {
if (uwsgi_send_http_stats(client_fd)) {
close(client_fd);
return;
}
}
struct uwsgi_stats *us = uwsgi_stats_new(8192);
if (uwsgi_stats_keyval_comma(us, "version", UWSGI_VERSION)) goto end;
+2
View File
@@ -1832,6 +1832,7 @@ struct uwsgi_server {
// the stats server
char *stats;
int stats_fd;
int stats_http;
uint64_t queue_size;
uint64_t queue_blocksize;
@@ -3394,6 +3395,7 @@ char *uwsgi_matheval_str(char *);
#endif
int uwsgi_kvlist_parse(char *, size_t, char, char, ...);
int uwsgi_send_http_stats(int);
void uwsgi_check_emperor(void);
#ifdef UWSGI_AS_SHARED_LIBRARY