]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: Expose native cum_req metric for a server
authorMarcin Deranek <marcin.deranek@booking.com>
Fri, 15 May 2020 16:32:51 +0000 (18:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 16 May 2020 20:40:03 +0000 (22:40 +0200)
Expose native cum_req metric for a server: so far it was calculated as a
sum or all responses. Rename it from Cum. HTTP Responses to Cum. HTTP
Requests to be consistent with Frontend and Backend.

contrib/prometheus-exporter/service-prometheus.c
src/http_ana.c
src/stats.c

index 54770ef5bbb1859273368f2e22d01b566a9d97aa..f7542d26bc4d3dc61d23f697911ad60152a79bbc 100644 (file)
@@ -2061,6 +2061,11 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                        case ST_F_LBTOT:
                                                metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
                                                break;
+                                       case ST_F_REQ_TOT:
+                                               if (px->mode != PR_MODE_HTTP)
+                                                       goto next_px;
+                                               metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
+                                               break;
                                        case ST_F_HRSP_1XX:
                                                if (px->mode != PR_MODE_HTTP)
                                                        goto next_px;
index f6e0eca3b2cf3d8c586a71bcb4409eef4ce73f98..5492b54fecca2e107798ab325db21a87d397da13 100644 (file)
@@ -1721,8 +1721,10 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
        if (n == 4)
                stream_inc_http_err_ctr(s);
 
-       if (objt_server(s->target))
+       if (objt_server(s->target)) {
                _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.p.http.rsp[n], 1);
+               _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.p.http.cum_req, 1);
+       }
 
        /* Adjust server's health based on status code. Note: status codes 501
         * and 505 are triggered on demand by client request, so we must not
index f76fd379081fa5418d8c24c3c7d8053140f12e96..754819734cc3c48d562d094c2abf4533f8687635 100644 (file)
@@ -1016,19 +1016,10 @@ static int stats_dump_fields_html(struct buffer *out,
 
                /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
                if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
-                       unsigned long long tot;
-
-                       tot  = stats[ST_F_HRSP_OTHER].u.u64;
-                       tot += stats[ST_F_HRSP_1XX].u.u64;
-                       tot += stats[ST_F_HRSP_2XX].u.u64;
-                       tot += stats[ST_F_HRSP_3XX].u.u64;
-                       tot += stats[ST_F_HRSP_4XX].u.u64;
-                       tot += stats[ST_F_HRSP_5XX].u.u64;
-
                        chunk_appendf(out,
                                      "<tr><th>New connections:</th><td>%s</td></tr>"
                                      "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
-                                     "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
+                                     "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
                                      "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
                                      "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
                                      "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
@@ -1042,13 +1033,19 @@ static int stats_dump_fields_html(struct buffer *out,
                                      U2H(stats[ST_F_REUSE].u.u64),
                                      (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
                                      (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0,
-                                     U2H(tot),
-                                     U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0,
-                                     U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0,
-                                     U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0,
-                                     U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0,
-                                     U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0,
-                                     U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0,
+                                     U2H(stats[ST_F_REQ_TOT].u.u64),
+                                     U2H(stats[ST_F_HRSP_1XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
+                                     U2H(stats[ST_F_HRSP_2XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
+                                     U2H(stats[ST_F_HRSP_3XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
+                                     U2H(stats[ST_F_HRSP_4XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
+                                     U2H(stats[ST_F_HRSP_5XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
+                                     U2H(stats[ST_F_HRSP_OTHER].u.u64), stats[ST_F_REQ_TOT].u.u64 ?
+                                     (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0,
                                      U2H(stats[ST_F_WREW].u.u64),
                                      U2H(stats[ST_F_EINT].u.u64));
                }
@@ -1796,6 +1793,7 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
 
        /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
        if (px->mode == PR_MODE_HTTP) {
+               stats[ST_F_REQ_TOT]    = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
                stats[ST_F_HRSP_1XX]   = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
                stats[ST_F_HRSP_2XX]   = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
                stats[ST_F_HRSP_3XX]   = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);