MINOR: mux-h1: add stat for total count of connections/streams

Add counters for total number of http1 connections/stream since haproxy
startup. Contrary to open_conn/stream, they are never reset to zero.
This commit is contained in:
Christopher Faulet 2021-11-26 18:12:04 +01:00
parent 60fa051e71
commit 3bca28c9fd
1 changed files with 15 additions and 0 deletions

View File

@ -268,6 +268,9 @@ INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
enum {
H1_ST_OPEN_CONN,
H1_ST_OPEN_STREAM,
H1_ST_TOTAL_CONN,
H1_ST_TOTAL_STREAM,
H1_STATS_COUNT /* must be the last member of the enum */
};
@ -277,11 +280,18 @@ static struct name_desc h1_stats[] = {
.desc = "Count of currently open connections" },
[H1_ST_OPEN_STREAM] = { .name = "h1_open_streams",
.desc = "Count of currently open streams" },
[H1_ST_TOTAL_CONN] = { .name = "h1_total_connections",
.desc = "Total number of connections" },
[H1_ST_TOTAL_STREAM] = { .name = "h1_total_streams",
};
static struct h1_counters {
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 */
} h1_counters;
static void h1_fill_stats(void *data, struct field *stats)
@ -290,6 +300,8 @@ static void h1_fill_stats(void *data, struct field *stats)
stats[H1_ST_OPEN_CONN] = mkf_u64(FN_GAUGE, counters->open_conns);
stats[H1_ST_OPEN_STREAM] = mkf_u64(FN_GAUGE, counters->open_streams);
stats[H1_ST_TOTAL_CONN] = mkf_u64(FN_COUNTER, counters->total_conns);
stats[H1_ST_TOTAL_STREAM] = mkf_u64(FN_COUNTER, counters->total_streams);
}
static struct stats_module h1_stats_module = {
@ -657,6 +669,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
}
HA_ATOMIC_INC(&h1s->h1c->px_counters->open_streams);
HA_ATOMIC_INC(&h1s->h1c->px_counters->total_streams);
h1s->h1c->flags = (h1s->h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED | H1C_F_ST_READY;
TRACE_LEAVE(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
@ -775,6 +788,7 @@ static struct h1s *h1c_bck_stream_new(struct h1c *h1c, struct conn_stream *cs, s
h1s->res.err_pos = -1;
HA_ATOMIC_INC(&h1c->px_counters->open_streams);
HA_ATOMIC_INC(&h1c->px_counters->total_streams);
TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
return h1s;
@ -933,6 +947,7 @@ static int h1_init(struct connection *conn, struct proxy *proxy, struct session
h1c->conn->xprt->subscribe(h1c->conn, h1c->conn->xprt_ctx, SUB_RETRY_RECV, &h1c->wait_event);
HA_ATOMIC_INC(&h1c->px_counters->open_conns);
HA_ATOMIC_INC(&h1c->px_counters->total_conns);
/* mux->wake will be called soon to complete the operation */
TRACE_LEAVE(H1_EV_H1C_NEW, conn, h1c->h1s);