From: Krzysztof Piotr Oledzki Date: Mon, 4 Jan 2010 15:03:09 +0000 (+0100) Subject: [MINOR]: stats: add show-legends to report additional informations X-Git-Tag: v1.4-dev6~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15514c21a29cea4f72a5097ebc5d444653b85592;p=thirdparty%2Fhaproxy.git [MINOR]: stats: add show-legends to report additional informations Supported informations, available via "tr/td title": - cap: capabilities (proxy) - mode: one of tcp, http or health (proxy) - id: SNMP ID (proxy, socket, server) - IP (socket, server) - cookie (backend, server) --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 46787e59db..8652505ed5 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -4084,6 +4084,19 @@ stats show-desc [ ] See also: "show-node", "stats enable", "stats uri" and "description" in global section. +stats show-legends + Enable reporting additional informations on the statistics page : + - cap: capabilities (proxy) + - mode: one of tcp, http or health (proxy) + - id: SNMP ID (proxy, socket, server) + - IP (socket, server) + - cookie (backend, server) + + Though this statement alone is enough to enable statistics reporting, it is + recommended to set all other settings in order to avoid relying on default + unobvious parameters. + + See also: "stats enable", "stats uri". stats realm Enable statistics and set authentication realm diff --git a/include/common/uri_auth.h b/include/common/uri_auth.h index 3a7fd9c741..64f818b89e 100644 --- a/include/common/uri_auth.h +++ b/include/common/uri_auth.h @@ -34,6 +34,7 @@ struct stat_scope { #define ST_HIDEVER 0x00000001 /* do not report the version and reldate */ #define ST_SHNODE 0x00000002 /* show node name */ #define ST_SHDESC 0x00000004 /* show description */ +#define ST_SHLGNDS 0x0000008 /* show legends */ /* later we may link them to support multiple URI matching */ struct uri_auth { diff --git a/include/proto/backend.h b/include/proto/backend.h index 7a248da1fc..a6f1c9f4d7 100644 --- a/include/proto/backend.h +++ b/include/proto/backend.h @@ -34,6 +34,7 @@ int assign_server_address(struct session *s); int assign_server_and_queue(struct session *s); int connect_server(struct session *s); int srv_redispatch_connect(struct session *t); +const char *backend_lb_algo_str(int algo); int backend_parse_balance(const char **args, char *err, int errlen, struct proxy *curproxy); diff --git a/src/backend.c b/src/backend.c index fedac396fa..34783f51e6 100644 --- a/src/backend.c +++ b/src/backend.c @@ -950,6 +950,33 @@ int be_downtime(struct proxy *px) { return now.tv_sec - px->last_change + px->down_time; } +/* + * This function returns a string containing the balancing + * mode of the proxy in a format suitable for stats. + */ + +const char *backend_lb_algo_str(int algo) { + + if (algo == BE_LB_ALGO_RR) + return "roundrobin"; + else if (algo == BE_LB_ALGO_SRR) + return "static-rr"; + else if (algo == BE_LB_ALGO_LC) + return "leastconn"; + else if (algo == BE_LB_ALGO_SH) + return "source"; + else if (algo == BE_LB_ALGO_UH) + return "uri"; + else if (algo == BE_LB_ALGO_PH) + return "url_param"; + else if (algo == BE_LB_ALGO_HH) + return "hdr"; + else if (algo == BE_LB_ALGO_RCH) + return "rdp-cookie"; + else + return NULL; +} + /* This function parses a "balance" statement in a backend section describing * . It returns -1 if there is any error, otherwise zero. If it * returns -1, it may write an error message into ther buffer, for at diff --git a/src/cfgparse.c b/src/cfgparse.c index 10013fe46b..20fb65721f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1963,7 +1963,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) curproxy->uri_auth = NULL; /* we must detach from the default config */ if (*(args[1]) == 0) { - Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable', 'hide-version', 'show-node', 'show-desc'.\n", file, linenum, args[0]); + Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable', 'hide-version', 'show-node', 'show-desc', 'show-legends'.\n", file, linenum, args[0]); err_code |= ERR_ALERT | ERR_FATAL; goto out; } else if (!strcmp(args[1], "uri")) { @@ -2032,6 +2032,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_ABORT; goto out; } + } else if (!strcmp(args[1], "show-legends")) { + if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { + Alert("parsing [%s:%d]: out of memory.\n", file, linenum); + err_code |= ERR_ALERT | ERR_ABORT; + goto out; + } } else if (!strcmp(args[1], "show-node")) { if (*args[2]) { diff --git a/src/dumpstats.c b/src/dumpstats.c index 576566de50..e51a314bc0 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -1231,8 +1231,30 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) chunk_printf(&msg, "\n" "" - "" "" "\n" @@ -1404,9 +1426,44 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) } if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { + chunk_printf(&msg, "" /* sessions rate: current, max, limit */ "" @@ -1536,8 +1593,40 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) "no check" }; chunk_printf(&msg, /* name */ - "" /* queue : current, max, limit */ "" @@ -1547,8 +1636,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) "" "state & SRV_BACKUP) ? "backup" : "active", - sv_state, px->id, sv->id, px->id, sv->id, sv->id, + px->id, sv->id, px->id, sv->id, sv->id, U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"), U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max), U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-")); @@ -1803,8 +1891,17 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { chunk_printf(&msg, /* name */ - "" /* queue : current, max */ ""
" - "" + "flags&ST_SHLGNDS) { + /* cap, mode, id */ + chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d", + proxy_cap_str(px->cap), proxy_mode_str(px->mode), + px->uuid); + + /* cookie */ + if (px->cookie_name) { + struct chunk src; + + chunk_printf(&msg, ", cookie: '"); + chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); + chunk_htmlencode(&msg, &src); + + chunk_printf(&msg, "'"); + } + + chunk_printf(&msg, "\""); + } + + chunk_printf(&msg, + ">" "%s%s
flags&ST_SHLGNDS) { + char str[INET6_ADDRSTRLEN], *fmt = NULL; + int port; + + chunk_printf(&msg, " title=\"IP: "); + + port = (l->addr.ss_family == AF_INET6) + ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) + : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); + + if (l->addr.ss_family == AF_INET) { + if (inet_ntop(AF_INET, + (const void *)&((struct sockaddr_in *)&l->addr)->sin_addr, + str, sizeof(str))) + fmt = "%s:%d"; + } else { + if (inet_ntop(AF_INET6, + (const void *)&((struct sockaddr_in6 *)(&l->addr))->sin6_addr, + str, sizeof(str))) + fmt = "[%s]:%d"; + } + + if (fmt) + chunk_printf(&msg, fmt, str, port); + else + chunk_printf(&msg, "(%s)", strerror(errno)); + + /* id */ + chunk_printf(&msg, ", id: %d", l->luid); + + chunk_printf(&msg, "\""); + } + chunk_printf(&msg, /* name, queue */ - "
" + ">" "%s 
" - "" + "
state & SRV_BACKUP) ? "backup" : "active", sv_state); + + if (uri->flags&ST_SHLGNDS) { + char str[INET6_ADDRSTRLEN]; + + chunk_printf(&msg, " title=\"IP: "); + + /* IP */ + if (inet_ntop(sv->addr.sin_family, &sv->addr.sin_addr, str, sizeof(str))) + chunk_printf(&msg, "%s:%d", str, htons(sv->addr.sin_port)); + else + chunk_printf(&msg, "(%s)", strerror(errno)); + + /* id */ + chunk_printf(&msg, ", id: %d", sv->puid); + + /* cookie */ + if (sv->cookie) { + struct chunk src; + + chunk_printf(&msg, ", cookie: '"); + + chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); + chunk_htmlencode(&msg, &src); + + chunk_printf(&msg, "'"); + } + + chunk_printf(&msg, "\""); + } + + chunk_printf(&msg, + ">" "%s%s%s%s%s%s%s
" - "" + "
flags&ST_SHLGNDS) { + /* balancing */ + + chunk_printf(&msg, " title=\"balancing: %s\"", + backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); + } + + chunk_printf(&msg, + ">" "Backend%s%s