]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: samples: implement bytes_in and bytes_out samples
authorWilliam Lallemand <wlallemand@haproxy.org>
Wed, 23 Aug 2023 14:45:05 +0000 (16:45 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 13 Sep 2023 12:54:50 +0000 (14:54 +0200)
%[bytes_in] and %[bytes_out] are equivalent to %U and %B tags in
log-format.

doc/configuration.txt
src/sample.c

index 14f6b906d806083dbf1f4c05940220eb882a4a5d..0a01e3c344d416c59171136b1c784d800455baef 100644 (file)
@@ -22063,6 +22063,13 @@ baseq : string
   instead of "base" allows one to properly identify the target resource, for
   statistics or caching use cases. See also "path", "pathq" and "base".
 
+
+bytes_in : integer
+  This returns the number of bytes uploaded from the client to the server.
+
+bytes_out integer
+   This is the number of bytes transmitted from the server to the client.
+
 capture.req.hdr(<idx>) : string
   This extracts the content of the header captured by the "capture request
   header", idx is the position of the capture keyword in the configuration.
@@ -23745,6 +23752,7 @@ Please refer to the table below for currently defined variables :
   |                          Others                                           |
   +---+------+------------------------------------------------------+---------+
   |   | %B   | bytes_read           (from server to client)         | numeric |
+  |   |      | %[bytes_out]                                         |         |
   +---+------+------------------------------------------------------+---------+
   | H | %CC  | captured_request_cookie                              | string  |
   +---+------+------------------------------------------------------+---------+
@@ -23769,6 +23777,7 @@ Please refer to the table below for currently defined variables :
   |   | %ST  | status_code                                          | numeric |
   +---+------+------------------------------------------------------+---------+
   |   | %U   | bytes_uploaded       (from client to server)         | numeric |
+  |   |      | %[bytes_in]                                          |         |
   +---+------+------------------------------------------------------+---------+
   |   | %ac  | actconn                                              |         |
   |   |      | %[act_conn]                                          | numeric |
index bbb17d39fe52b30b125d9f3c70bad358dcd9dbe1..07c881dcf7bdf1f77873ce744fb191904ea2e9f6 100644 (file)
@@ -4905,9 +4905,35 @@ error:
        return 0;
 }
 
+/* bytes_{in,out} */
+static int smp_fetch_bytes(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       struct strm_logs *logs;
+
+       if (!smp->strm)
+               return 0;
+
+       smp->data.type = SMP_T_SINT;
+       smp->flags = 0;
+
+       logs = &smp->strm->logs;
+       if (!logs)
+               return 0;
+
+       if (kw[6] == 'i') { /* bytes_in */
+               smp->data.u.sint = logs->bytes_in;
+       } else { /* bytes_out */
+               smp->data.u.sint = logs->bytes_out;
+       }
+
+       return 1;
+}
 
 
 static struct sample_fetch_kw_list smp_logs_kws = {ILH, {
+       { "bytes_in",             smp_fetch_bytes,        0,         NULL, SMP_T_SINT, SMP_USE_INTRN },
+       { "bytes_out",            smp_fetch_bytes,        0,         NULL, SMP_T_SINT, SMP_USE_INTRN },
+
        { "txn.timer.total",      smp_fetch_txn_timers,   0,         NULL, SMP_T_SINT, SMP_USE_TXFIN }, /* "Ta" */
        { "txn.timer.user",       smp_fetch_txn_timers,   0,         NULL, SMP_T_SINT, SMP_USE_TXFIN }, /* "Tu" */