]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stconn: Add counters to SC to know number of bytes received and sent
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 4 Nov 2025 16:46:10 +0000 (17:46 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Nov 2025 14:01:28 +0000 (15:01 +0100)
<bytes_in> and <bytes_out> counters were added to SC to count, respectively,
the number of bytes received from an endpoint or sent to an endpoint. These
counters are updated for connections and applets.

This patch is related to issue #1617.

include/haproxy/stconn-t.h
src/stconn.c
src/stream.c

index 2195ea14b15fdcfcf9c0b841b06da1d0274ede4b..f93c5b6f65823f3698c62d28df0208947baa06ad 100644 (file)
@@ -377,6 +377,9 @@ struct stconn {
                                              *    -1   : the SC is waiting for room but not on a specific amount of data
                                              *    >= 0 : min free space required to progress. 0 means SC must be unblocked ASAP
                                              */
+       unsigned long long bytes_in;         /* total number of bytes received from the SE */
+       unsigned long long bytes_out;        /* total number of bytes sent to the SE */
+
        struct wait_event wait_event;        /* We're in a wait list */
        struct sedesc *sedesc;               /* points to the stream endpoint descriptor */
        enum obj_type *app;                  /* points to the applicative point (stream or check) */
index 4b27e5314e1a26b8dbd4b894fda62660bf0bbbe3..41d0fe3965f81fb2db3c7d072a1b31f2caf299c9 100644 (file)
@@ -211,6 +211,7 @@ static struct stconn *sc_new(struct sedesc *sedesc)
        sc->app_ops = NULL;
        sc->src = NULL;
        sc->dst = NULL;
+       sc->bytes_in = sc->bytes_out = 0;
        sc->wait_event.tasklet = NULL;
        sc->wait_event.events = 0;
 
@@ -550,6 +551,7 @@ int sc_reset_endp(struct stconn *sc)
        BUG_ON(sc->sedesc);
        sc->sedesc = new_sd;
        sc->sedesc->sc = sc;
+       sc->bytes_in = sc->bytes_out = 0;
        sc_ep_set(sc, SE_FL_DETACHED);
        return 0;
 }
@@ -1352,6 +1354,7 @@ int sc_conn_recv(struct stconn *sc)
                else if (ret > 0) {
                        if (ic->to_forward != CHN_INFINITE_FORWARD)
                                ic->to_forward -= ret;
+                       sc->bytes_in += ret;
                        ic->total += ret;
                        cur_read += ret;
                        ic->flags |= CF_READ_EVENT;
@@ -1454,6 +1457,7 @@ int sc_conn_recv(struct stconn *sc)
                }
 
                ic->flags |= CF_READ_EVENT;
+               sc->bytes_in += ret;
                ic->total += ret;
 
                /* End-of-input reached, we can leave. In this case, it is
@@ -1662,8 +1666,10 @@ int sc_conn_send(struct stconn *sc)
                        send_flag |= CO_SFL_STREAMER;
 
                ret = conn->mux->resume_fastfwd(sc, send_flag);
-               if (ret > 0)
+               if (ret > 0) {
+                       sc->bytes_out += ret;
                        did_send = 1;
+               }
 
                if (sc_ep_have_ff_data(sc))
                        goto end;
@@ -1736,7 +1742,7 @@ int sc_conn_send(struct stconn *sc)
                        did_send = 1;
                        c_rew(oc, ret);
                        c_realign_if_empty(oc);
-
+                       sc->bytes_out += ret;
                        if (!co_data(oc)) {
                                /* Always clear both flags once everything has been sent, they're one-shot */
                                sc->flags &= ~(SC_FL_SND_ASAP|SC_FL_SND_EXP_MORE);
@@ -2032,6 +2038,7 @@ int sc_applet_recv(struct stconn *sc)
                else if (ret > 0) {
                        if (ic->to_forward != CHN_INFINITE_FORWARD)
                                ic->to_forward -= ret;
+                       sc->bytes_in += ret;
                        ic->total += ret;
                        cur_read += ret;
                        ic->flags |= CF_READ_EVENT;
@@ -2115,6 +2122,7 @@ int sc_applet_recv(struct stconn *sc)
        }
 
        ic->flags |= CF_READ_EVENT;
+       sc->bytes_in += ret;
        ic->total += ret;
 
        /* End-of-input reached, we can leave. In this case, it is
@@ -2263,7 +2271,7 @@ int sc_applet_send(struct stconn *sc)
                        did_send = 1;
                        c_rew(oc, ret);
                        c_realign_if_empty(oc);
-
+                       sc->bytes_out += ret;
                        if (!co_data(oc)) {
                                /* Always clear both flags once everything has been sent, they're one-shot */
                                sc->flags &= ~(SC_FL_SND_ASAP|SC_FL_SND_EXP_MORE);
index ccb3ecd4eecaf410418cdd7129e70aae9e460de7..07b6523ad353e33b08f9627f62027a40bed834c5 100644 (file)
@@ -299,6 +299,7 @@ int stream_upgrade_from_sc(struct stconn *sc, struct buffer *input)
                s->req.buf = *input;
                *input = BUF_NULL;
                s->req.total = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf));
+               s->scf->bytes_in = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf));
                sc_ep_report_read_activity(s->scf);
        }
 
@@ -573,6 +574,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
                s->req.buf = *input;
                *input = BUF_NULL;
                s->req.total = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf));
+               s->scf->bytes_in = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf));
                sc_ep_report_read_activity(s->scf);
        }