]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux_h2: add stat for total count of connections/streams
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 3 Nov 2020 14:04:45 +0000 (15:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 3 Nov 2020 16:04:22 +0000 (17:04 +0100)
Add counters for total number of http2 connections/stream since haproxy
startup. Contrary to open_conn/stream, they are never reset to zero.

src/mux_h2.c

index c4707354bb8b07701c31d4e5be17c85678089552..aa0a7602952f70fb0df0bfcd475c51e0bfa5e5ac 100644 (file)
@@ -393,6 +393,8 @@ enum {
 
        H2_ST_OPEN_CONN,
        H2_ST_OPEN_STREAM,
+       H2_ST_TOTAL_CONN,
+       H2_ST_TOTAL_STREAM,
 
        H2_STATS_COUNT /* must be the last member of the enum */
 };
@@ -418,10 +420,14 @@ static struct name_desc h2_stats[] = {
        [H2_ST_GOAWAY_RESP]     = { .name = "h2_goaway_resp",
                                    .desc = "Total number of GOAWAY sent on detected error" },
 
-       [H2_ST_OPEN_CONN]   = { .name = "h2_open_connections",
-                               .desc = "Count of currently open connections" },
-       [H2_ST_OPEN_STREAM] = { .name = "h2_backend_open_streams",
-                               .desc = "Count of currently open streams" },
+       [H2_ST_OPEN_CONN]    = { .name = "h2_open_connections",
+                                .desc = "Count of currently open connections" },
+       [H2_ST_OPEN_STREAM]  = { .name = "h2_backend_open_streams",
+                                .desc = "Count of currently open streams" },
+       [H2_ST_TOTAL_CONN]   = { .name = "h2_open_connections",
+                                .desc = "Total number of connections" },
+       [H2_ST_TOTAL_STREAM] = { .name = "h2_backend_open_streams",
+                                .desc = "Total number of streams" },
 };
 
 static struct h2_counters {
@@ -436,8 +442,10 @@ static struct h2_counters {
        long long rst_stream_resp; /* total number of RST_STREAM frame sent on error */
        long long goaway_resp;     /* total number of GOAWAY frame sent on error */
 
-       long long open_conns;   /* count of currently open connections */
-       long long open_streams; /* count of currently open streams */
+       long long open_conns;    /* count of currently open connections */
+       long long open_streams;  /* count of currently open streams */
+       long long total_conns;   /* total number of connections */
+       long long total_streams; /* total number of streams */
 } h2_counters;
 
 static void h2_fill_stats(void *data, struct field *stats)
@@ -455,8 +463,10 @@ static void h2_fill_stats(void *data, struct field *stats)
        stats[H2_ST_RST_STREAM_RESP] = mkf_u64(FN_COUNTER, counters->rst_stream_resp);
        stats[H2_ST_GOAWAY_RESP]     = mkf_u64(FN_COUNTER, counters->goaway_resp);
 
-       stats[H2_ST_OPEN_CONN]   = mkf_u64(FN_GAUGE, counters->open_conns);
-       stats[H2_ST_OPEN_STREAM] = mkf_u64(FN_GAUGE, counters->open_streams);
+       stats[H2_ST_OPEN_CONN]    = mkf_u64(FN_GAUGE,   counters->open_conns);
+       stats[H2_ST_OPEN_STREAM]  = mkf_u64(FN_GAUGE,   counters->open_streams);
+       stats[H2_ST_TOTAL_CONN]   = mkf_u64(FN_COUNTER, counters->total_conns);
+       stats[H2_ST_TOTAL_STREAM] = mkf_u64(FN_COUNTER, counters->total_streams);
 }
 
 static struct stats_module h2_stats_module = {
@@ -989,6 +999,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
        }
 
        HA_ATOMIC_ADD(&h2c->px_counters->open_conns, 1);
+       HA_ATOMIC_ADD(&h2c->px_counters->total_conns, 1);
 
        /* prepare to read something */
        h2c_restart_reading(h2c, 1);
@@ -1448,6 +1459,7 @@ static struct h2s *h2s_new(struct h2c *h2c, int id)
        h2c->stream_cnt++;
 
        HA_ATOMIC_ADD(&h2c->px_counters->open_streams, 1);
+       HA_ATOMIC_ADD(&h2c->px_counters->total_streams, 1);
 
        TRACE_LEAVE(H2_EV_H2S_NEW, h2c->conn, h2s);
        return h2s;