[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.
This commit is contained in:
Willy Tarreau 2009-10-10 18:37:29 +02:00
parent 975c50b838
commit 38338fa0a0
2 changed files with 42 additions and 1 deletions

View File

@ -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 <backend>/<server>
Report the current weight and the initial weight of server <server> in
backend <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:

View File

@ -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 <line> 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;