From f157384803ba89b71a811dbd4954443526498cad Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 14 Dec 2018 11:35:36 +0100 Subject: [PATCH] MINOR: backend: count the number of connect and reuse per server and per backend Sadly we didn't have the cumulated number of connections established to servers till now, so let's now update it per backend and per-server and report it in the stats. On the stats page it appears in the tooltip when hovering over the total sessions count field. --- include/types/counters.h | 2 ++ include/types/stats.h | 2 ++ src/backend.c | 8 ++++++++ src/stats.c | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/include/types/counters.h b/include/types/counters.h index fd83ebbe7f..79dd6d4376 100644 --- a/include/types/counters.h +++ b/include/types/counters.h @@ -83,6 +83,8 @@ struct be_counters { long long denied_req; /* blocked requests because of security concerns */ long long denied_resp; /* blocked responses because of security concerns */ + long long connect; /* number of connection establishment attempts */ + long long reuse; /* number of connection reuses */ long long failed_conns; /* failed connect() attempts (BE only) */ long long failed_resp; /* failed responses (BE only) */ long long cli_aborts; /* aborted responses during DATA phase caused by the client */ diff --git a/include/types/stats.h b/include/types/stats.h index a188667e89..c3b9fc8fc7 100644 --- a/include/types/stats.h +++ b/include/types/stats.h @@ -392,6 +392,8 @@ enum stat_field { ST_F_DCON, ST_F_DSES, ST_F_WREW, + ST_F_CONNECT, + ST_F_REUSE, /* must always be the last one */ ST_F_TOTAL_FIELDS diff --git a/src/backend.c b/src/backend.c index 34a04c35b3..bb9b4ea665 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1376,6 +1376,14 @@ int connect_server(struct stream *s) if (s->be->options & PR_O_TCP_NOLING) s->si[1].flags |= SI_FL_NOLINGER; + if (s->flags & SF_SRV_REUSED) { + HA_ATOMIC_ADD(&s->be->be_counters.reuse, 1); + HA_ATOMIC_ADD(&srv->counters.reuse, 1); + } else { + HA_ATOMIC_ADD(&s->be->be_counters.connect, 1); + HA_ATOMIC_ADD(&srv->counters.connect, 1); + } + err = si_connect(&s->si[1], srv_conn); #ifdef USE_OPENSSL diff --git a/src/stats.c b/src/stats.c index be70dde3aa..76561ef930 100644 --- a/src/stats.c +++ b/src/stats.c @@ -228,6 +228,8 @@ const char *stat_field_names[ST_F_TOTAL_FIELDS] = { [ST_F_DCON] = "dcon", [ST_F_DSES] = "dses", [ST_F_WREW] = "wrew", + [ST_F_CONNECT] = "connect", + [ST_F_REUSE] = "reuse", }; /* one line of info */ @@ -960,6 +962,8 @@ static int stats_dump_fields_html(struct buffer *out, tot += stats[ST_F_HRSP_5XX].u.u64; chunk_appendf(out, + "New connections:%s" + "Reused connections:%s(%d%%)" "Cum. HTTP responses:%s" "- HTTP 1xx responses:%s(%d%%)" "- HTTP 2xx responses:%s(%d%%)" @@ -969,6 +973,10 @@ static int stats_dump_fields_html(struct buffer *out, "- other responses:%s(%d%%)" "Failed hdr rewrites:%s" "", + U2H(stats[ST_F_CONNECT].u.u64), + 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, @@ -1180,6 +1188,8 @@ 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) { chunk_appendf(out, + "New connections:%s" + "Reused connections:%s(%d%%)" "Cum. HTTP requests:%s" "- HTTP 1xx responses:%s" "- HTTP 2xx responses:%s" @@ -1191,6 +1201,10 @@ static int stats_dump_fields_html(struct buffer *out, "Failed hdr rewrites:%s" "Avg over last 1024 success. conn." "", + U2H(stats[ST_F_CONNECT].u.u64), + 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(stats[ST_F_REQ_TOT].u.u64), U2H(stats[ST_F_HRSP_1XX].u.u64), U2H(stats[ST_F_HRSP_2XX].u.u64), @@ -1596,6 +1610,8 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); + stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect); + stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse); /* status */ fld_status = chunk_newstr(out); @@ -1789,6 +1805,8 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); + stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect); + stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse); stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); stats[ST_F_ACT] = mkf_u32(0, px->srv_act);