]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stats page: added links for 'refresh' and 'hide down'
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Jul 2007 12:43:32 +0000 (14:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 Sep 2007 19:09:29 +0000 (21:09 +0200)
The stats page now supports an option to hide servers which are DOWN
and to enable/disable automatic refresh. It is also possible to ask
for an immediate refresh.

include/types/session.h
src/proto_http.c

index 819acfd74aa5ed039e63b9f5f5459ea397b543ec..a76861912c3c1bf3d48157aaefbdeecd2dbbe147 100644 (file)
@@ -74,6 +74,9 @@
 #define        SN_FINST_SHIFT  12              /* bit shift */
 /* unused:              0x00008000 */
 
+#define SN_STAT_HIDEDWN        0x00010000      /* hide 'down' servers in the stats page */
+#define SN_STAT_NORFRSH        0x00020000      /* do not automatically refresh the stats page */
+
 
 /* WARNING: if new fields are added, they must be initialized in event_accept()
  * and freed in session_free() !
index 8ebdc6116a516822e9c67fab497a24a495f79401..7a86d115930c4cc2eddef4e3383bd44bfc249b13 100644 (file)
@@ -3453,7 +3453,7 @@ int produce_content_stats(struct session *s)
                             "Connection: close\r\n"
                             "Content-Type: text/html\r\n");
 
-               if (s->be->uri_auth->refresh > 0)
+               if (s->be->uri_auth->refresh > 0 && !(s->flags & SN_STAT_NORFRSH))
                        chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n",
                                     s->be->uri_auth->refresh);
 
@@ -3569,7 +3569,7 @@ int produce_content_stats(struct session *s)
                             "<h2>Statistics Report for pid %d</h2>\n"
                             "<hr width=\"100%%\" class=\"hr\">\n"
                             "<h3>&gt; General process information</h3>\n"
-                            "<table border=0 cols=3><tr><td align=\"left\" nowrap width=\"1%%\">\n"
+                            "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
                             "<p><b>pid = </b> %d (nbproc = %d)<br>\n"
                             "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
                             "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n"
@@ -3590,14 +3590,8 @@ int produce_content_stats(struct session *s)
                             "<td class=\"active4\"></td><td class=\"noborder\">not checked </td>"
                             "</tr></table>\n"
                             "</td>"
-                            "<td align=\"left\" nowrap width=\"1%%\">"
-                            "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
-                            "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
-                            "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
-                            "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
-                            "</ul>"
-                            "</td>"
-                            "</tr></table>\n"
+                            "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
+                            "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
                             "",
                             pid, pid, global.nbproc,
                             up / 86400, (up % 86400) / 3600,
@@ -3610,6 +3604,53 @@ int produce_content_stats(struct session *s)
                             actconn
                             );
            
+               if (s->flags & SN_STAT_HIDEDWN)
+                       chunk_printf(&msg, sizeof(trash),
+                                    "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
+                                    s->be->uri_auth->uri_prefix,
+                                    "",
+                                    (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
+               else
+                       chunk_printf(&msg, sizeof(trash),
+                                    "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
+                                    s->be->uri_auth->uri_prefix,
+                                    ";up",
+                                    (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
+
+               if (s->be->uri_auth->refresh > 0) {
+                       if (s->flags & SN_STAT_NORFRSH)
+                               chunk_printf(&msg, sizeof(trash),
+                                            "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
+                                            s->be->uri_auth->uri_prefix,
+                                            (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
+                                            "");
+                       else
+                               chunk_printf(&msg, sizeof(trash),
+                                            "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
+                                            s->be->uri_auth->uri_prefix,
+                                            (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
+                                            ";norefresh");
+               }
+
+               chunk_printf(&msg, sizeof(trash),
+                            "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
+                            s->be->uri_auth->uri_prefix,
+                            (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
+                            (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
+
+               chunk_printf(&msg, sizeof(trash),
+                            "</td>"
+                            "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
+                            "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
+                            "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
+                            "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
+                            "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
+                            "</ul>"
+                            "</td>"
+                            "</tr></table>\n"
+                            ""
+                            );
+           
                if (buffer_write_chunk(rep, &msg) != 0)
                        return 0;
 
@@ -3793,6 +3834,12 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
                                else
                                        sv_state = 0; /* DOWN */
 
+                       if ((sv_state == 0) && (s->flags & SN_STAT_HIDEDWN)) {
+                               /* do not report servers which are DOWN */
+                               s->data_ctx.stats.sv = sv->next;
+                               continue;
+                       }
+
                        chunk_printf(&msg, sizeof(trash),
                                     /* name */
                                     "<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
@@ -5189,6 +5236,26 @@ int stats_check_uri_auth(struct session *t, struct proxy *backend)
        if (memcmp(h, uri_auth->uri_prefix, uri_auth->uri_len) != 0)
                return 0;
 
+       h += uri_auth->uri_len;
+       while (h <= t->req->data + txn->req.sl.rq.u + txn->req.sl.rq.u_l - 3) {
+               if (memcmp(h, ";up", 3) == 0) {
+                       t->flags |= SN_STAT_HIDEDWN;
+                       break;
+               }
+               h++;
+       }
+
+       if (uri_auth->refresh) {
+               h = t->req->data + txn->req.sl.rq.u + uri_auth->uri_len;
+               while (h <= t->req->data + txn->req.sl.rq.u + txn->req.sl.rq.u_l - 10) {
+                       if (memcmp(h, ";norefresh", 10) == 0) {
+                               t->flags |= SN_STAT_NORFRSH;
+                               break;
+                       }
+                       h++;
+               }
+       }
+
        /* we are in front of a interceptable URI. Let's check
         * if there's an authentication and if it's valid.
         */