[MAJOR] make unix sockets work again with stats

The unix protocol handler had not been updated during the last
stream_sock changes. This has been done now. There is still a
lot of duplicated code between session.c and proto_uxst.c due
to the way the session is handled. Session.c relies on the existence
of a frontend while it does not exist here.

It is easier to see the difference between the stats part (placed
in dumpstats.c) and the unix-stream part (in proto_uxst.c).

The hijacking function still needs to be dynamically set into the
response buffer, and some cleanup is still required, then all those
changes should be forward-ported to the HTTP part. Adding support
for new keywords should not cause trouble now.
This commit is contained in:
Willy Tarreau 2008-12-07 16:06:43 +01:00
parent ff8d42ea68
commit b1356cf4e4
4 changed files with 400 additions and 925 deletions

View File

@ -4,7 +4,7 @@
statistics output. statistics output.
Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1 License as published by the Free Software Foundation, version 2.1
@ -39,7 +39,13 @@
#define STATS_TYPE_BE 1 #define STATS_TYPE_BE 1
#define STATS_TYPE_SV 2 #define STATS_TYPE_SV 2
#define STATS_ST_INIT 0
#define STATS_ST_REQ 1
#define STATS_ST_REP 2
#define STATS_ST_CLOSE 3
int stats_dump_raw(struct session *s, struct uri_auth *uri); int stats_dump_raw(struct session *s, struct uri_auth *uri);
int stats_dump_raw_to_buffer(struct session *s, struct buffer *req);
int stats_dump_http(struct session *s, struct uri_auth *uri); int stats_dump_http(struct session *s, struct uri_auth *uri);
int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri); int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri);

View File

@ -29,6 +29,7 @@
int uxst_event_accept(int fd); int uxst_event_accept(int fd);
void uxst_add_listener(struct listener *listener); void uxst_add_listener(struct listener *listener);
void process_uxst_stats(struct task *t, int *next); void process_uxst_stats(struct task *t, int *next);
void uxst_process_session(struct task *t, int *next);
#endif /* _PROTO_PROTO_UXST_H */ #endif /* _PROTO_PROTO_UXST_H */

View File

@ -78,7 +78,8 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
global.stats_sock.state = LI_INIT; global.stats_sock.state = LI_INIT;
global.stats_sock.options = LI_O_NONE; global.stats_sock.options = LI_O_NONE;
global.stats_sock.accept = uxst_event_accept; global.stats_sock.accept = uxst_event_accept;
global.stats_sock.handler = process_uxst_stats; global.stats_sock.handler = uxst_process_session;
global.stats_sock.analysers = AN_REQ_UNIX_STATS;
global.stats_sock.private = NULL; global.stats_sock.private = NULL;
cur_arg = 2; cur_arg = 2;
@ -122,7 +123,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
return -1; return -1;
} }
} }
uxst_add_listener(&global.stats_sock); uxst_add_listener(&global.stats_sock);
global.maxsock++; global.maxsock++;
} }
@ -287,6 +288,23 @@ int stats_dump_raw(struct session *s, struct uri_auth *uri)
} }
/* This function is called to send output to the response buffer. It simply
* calls stats_dump_raw(), and releases the buffer's hijack bit when the dump
* is finished. It always returns 0.
*/
int stats_dump_raw_to_buffer(struct session *s, struct buffer *req)
{
if (s->ana_state != STATS_ST_REP)
return 0;
if (stats_dump_raw(s, NULL) != 0) {
buffer_stop_hijack(s->rep);
s->ana_state = STATS_ST_CLOSE;
}
return 0;
}
/* /*
* Produces statistics data for the session <s>. Expects to be called with * Produces statistics data for the session <s>. Expects to be called with
* client socket shut down on input. It stops by itself by unsetting the * client socket shut down on input. It stops by itself by unsetting the
@ -480,7 +498,7 @@ int stats_dump_http(struct session *s, struct uri_auth *uri)
global.maxconn, global.maxconn,
actconn actconn
); );
if (s->data_ctx.stats.flags & STAT_HIDE_DOWN) if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
chunk_printf(&msg, sizeof(trash), chunk_printf(&msg, sizeof(trash),
"<li><a href=\"%s%s%s\">Show all servers</a><br>\n", "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
@ -532,7 +550,7 @@ int stats_dump_http(struct session *s, struct uri_auth *uri)
"</tr></table>\n" "</tr></table>\n"
"" ""
); );
if (buffer_write_chunk(rep, &msg) >= 0) if (buffer_write_chunk(rep, &msg) >= 0)
return 0; return 0;
} }
@ -811,7 +829,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
sv->failed_secu, sv->failed_secu,
sv->failed_conns, sv->failed_resp, sv->failed_conns, sv->failed_resp,
sv->retries, sv->redispatches); sv->retries, sv->redispatches);
/* status */ /* status */
chunk_printf(&msg, sizeof(trash), "<td nowrap>"); chunk_printf(&msg, sizeof(trash), "<td nowrap>");
@ -889,7 +907,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
sv->failed_secu, sv->failed_secu,
sv->failed_conns, sv->failed_resp, sv->failed_conns, sv->failed_resp,
sv->retries, sv->redispatches); sv->retries, sv->redispatches);
/* status */ /* status */
chunk_printf(&msg, sizeof(trash), chunk_printf(&msg, sizeof(trash),
srv_hlt_st[sv_state], srv_hlt_st[sv_state],
@ -1043,7 +1061,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
if (buffer_write_chunk(rep, &msg) >= 0) if (buffer_write_chunk(rep, &msg) >= 0)
return 0; return 0;
} }
s->data_ctx.stats.px_st = DATA_ST_PX_END; s->data_ctx.stats.px_st = DATA_ST_PX_END;
/* fall through */ /* fall through */

File diff suppressed because it is too large Load Diff