]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stats: add the "get weight" command to report a server's weight
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 16:37:29 +0000 (18:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 17:39:21 +0000 (19:39 +0200)
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.

doc/configuration.txt
src/dumpstats.c

index 8386e6f295cf222ef8cae054ddbd78e992653906..82b73b3ab65ebae63ae04a7956247881ec945f1f 100644 (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:
index dcbccf7ca2cd73c370ad0729a44cd7a12c194d22..e576b12e76c48a1dcd939d50c6f763032afe146e 100644 (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;