From: Willy Tarreau Date: Sat, 10 Oct 2009 16:37:29 +0000 (+0200) Subject: [MEDIUM] stats: add the "get weight" command to report a server's weight X-Git-Tag: v1.4-dev4~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38338fa0a0f7d159aa3e1228b503572708822606;p=thirdparty%2Fhaproxy.git [MEDIUM] stats: add the "get weight" command to report a server's weight This command is unrestricted and simply reports a server's weight, as well as the weight initially configured, which at the moment are the sames. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 8386e6f295..82b73b3ab6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -6870,6 +6870,12 @@ clear counters all server. This has the same effect as restarting. This command is restricted and can only be issued on sockets configured for level "admin". +get weight / + Report the current weight and the initial weight of server in + backend or an error if either doesn't exist. The initial weight is + the one that appears in the configuration file. Both are normally equal + unless the current weight has been changed. + /* * Local variables: diff --git a/src/dumpstats.c b/src/dumpstats.c index dcbccf7ca2..e576b12e76 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -62,6 +62,7 @@ const char stats_sock_usage_msg[] = " show stat : report counters for each proxy and server\n" " show errors : report last request and response errors for each proxy\n" " show sess : report the list of current sessions\n" + " get weight : report a server's current weight\n" ""; const char stats_permission_denied_msg[] = @@ -377,7 +378,41 @@ int stats_sock_parse_request(struct stream_interface *si, char *line) return 0; } } - else { /* not "show" nor "clear"*/ + else if (strcmp(args[0], "get") == 0) { + if (strcmp(args[1], "weight") == 0) { + struct proxy *px; + struct server *sv; + + /* split "backend/server" and make point to server */ + for (line = args[2]; *line; line++) + if (*line == '/') { + *line++ = '\0'; + break; + } + + if (!*line) { + buffer_feed(si->ib, "Require 'backend/server'.\n"); + return 1; + } + + if (!get_backend_server(args[2], line, &px, &sv)) { + if (!px) + buffer_feed(si->ib, "No such backend.\n"); + else + buffer_feed(si->ib, "No such server.\n"); + return 1; + } + + /* return server's effective weight at the moment */ + snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight); + buffer_feed(si->ib, trash); + return 1; + } + else { /* not "get weight" */ + return 0; + } + } + else { /* not "show" nor "clear" nor "get" */ return 0; } return 1;