]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: replace STAT_FMT_CSV with STAT_FMT_HTML
authorWilly Tarreau <w@1wt.eu>
Sun, 23 Dec 2012 17:15:23 +0000 (18:15 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 23 Dec 2012 20:46:30 +0000 (21:46 +0100)
We need to switch the default mode if we want to add new output formats
later. Let CSV be the default and HTML be an option.

include/proto/dumpstats.h
src/dumpstats.c
src/proto_http.c

index e9b2f76e11dc6831fa63d2e6428892d81e3a30bd..0674c323a7e60e1f4df80a51caf14c834951eb0e 100644 (file)
@@ -27,7 +27,7 @@
 #include <types/stream_interface.h>
 
 /* Flags for applet.ctx.stats.flags */
-#define STAT_FMT_CSV    0x00000001     /* dump the stats in CSV format instead of HTML */
+#define STAT_FMT_HTML   0x00000001      /* dump the stats in HTML format */
 #define STAT_HIDE_DOWN  0x00000008     /* hide 'down' servers in the stats page */
 #define STAT_NO_REFRESH 0x00000010     /* do not automatically refresh the stats page */
 #define STAT_ADMIN      0x00000020     /* indicate a stats admin level */
index 3a890f3c15225a0859af585f6902ec9b5ec97ed7..24de6d0a0072a16f5faf9f67afc92c24e39d960b 100644 (file)
@@ -941,12 +941,10 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                si->applet.ctx.stats.sid = atoi(args[4]);
                        }
 
-                       si->applet.ctx.stats.flags |= STAT_FMT_CSV;
                        si->conn->xprt_st = STAT_ST_INIT;
                        si->applet.st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer
                }
                else if (strcmp(args[1], "info") == 0) {
-                       si->applet.ctx.stats.flags |= STAT_FMT_CSV;
                        si->conn->xprt_st = STAT_ST_INIT;
                        si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer
                }
@@ -1815,7 +1813,7 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
        if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))
                return 0;
 
-       if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+       if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                chunk_appendf(&trash,
                              /* name, queue */
                              "<tr class=\"frontend\">");
@@ -2020,7 +2018,7 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
  */
 static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
 {
-       if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+       if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                chunk_appendf(&trash, "<tr class=socket>");
                if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
                        /* Column sub-heading for Enable or Disable server */
@@ -2152,7 +2150,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
        struct chunk src;
        int i;
 
-       if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { /* HTML mode */
+       if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                static char *srv_hlt_st[7] = {
                        "DOWN",
                        "DN %d/%d &uarr;",
@@ -2532,7 +2530,7 @@ static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, in
        if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))
                return 0;
 
-       if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { /* HTML mode */
+       if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                chunk_appendf(&trash, "<tr class=\"backend\">");
                if (px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
                        /* Column sub-heading for Enable or Disable server */
@@ -2894,7 +2892,7 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy
                /* fall through */
 
        case STAT_PX_ST_TH:
-               if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+               if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                        stats_dump_html_px_hdr(si, px, uri);
                        if (bi_putchk(rep, &trash) == -1)
                                return 0;
@@ -3006,7 +3004,7 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy
                /* fall through */
 
        case STAT_PX_ST_END:
-               if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+               if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                        stats_dump_html_px_end(si, px);
                        if (bi_putchk(rep, &trash) == -1)
                                return 0;
@@ -3346,10 +3344,10 @@ static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_aut
                /* fall through */
 
        case STAT_ST_HEAD:
-               if (si->applet.ctx.stats.flags & STAT_FMT_CSV)
-                       stats_dump_csv_header();
-               else
+               if (si->applet.ctx.stats.flags & STAT_FMT_HTML)
                        stats_dump_html_head(uri);
+               else
+                       stats_dump_csv_header();
 
                if (bi_putchk(rep, &trash) == -1)
                        return 0;
@@ -3358,7 +3356,7 @@ static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_aut
                /* fall through */
 
        case STAT_ST_INFO:
-               if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+               if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                        stats_dump_html_info(si, uri);
                        if (bi_putchk(rep, &trash) == -1)
                                return 0;
@@ -3390,7 +3388,7 @@ static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_aut
                /* fall through */
 
        case STAT_ST_END:
-               if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
+               if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
                        stats_dump_html_end();
                        if (bi_putchk(rep, &trash) == -1)
                                return 0;
index 60b630dc3a884fe4aea7b084e94bf8ab68ce8765..d49ef05535b67ef3dfd23c5d8dbd87f775c14af4 100644 (file)
@@ -3022,7 +3022,7 @@ int http_handle_stats(struct session *s, struct channel *req)
                     "Cache-Control: no-cache\r\n"
                     "Connection: close\r\n"
                     "Content-Type: %s\r\n",
-                    (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
+                    (si->applet.ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
 
        if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH))
                chunk_appendf(&trash, "Refresh: %d\r\n",
@@ -7651,6 +7651,7 @@ int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct pr
 
        memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats));
        si->applet.ctx.stats.st_code = STAT_STATUS_INIT;
+       si->applet.ctx.stats.flags |= STAT_FMT_HTML; /* assume HTML mode by default */
 
        /* check URI size */
        if (uri_auth->uri_len > msg->sl.rq.u_l)
@@ -7683,7 +7684,7 @@ int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct pr
        h = uri + uri_auth->uri_len;
        while (h <= uri + msg->sl.rq.u_l - 4) {
                if (memcmp(h, ";csv", 4) == 0) {
-                       si->applet.ctx.stats.flags |= STAT_FMT_CSV;
+                       si->applet.ctx.stats.flags &= ~STAT_FMT_HTML;
                        break;
                }
                h++;