From: William Lallemand Date: Wed, 23 Aug 2023 14:45:05 +0000 (+0200) Subject: MINOR: samples: implement bytes_in and bytes_out samples X-Git-Tag: v2.9-dev6~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7424a1ba;p=thirdparty%2Fhaproxy.git MINOR: samples: implement bytes_in and bytes_out samples %[bytes_in] and %[bytes_out] are equivalent to %U and %B tags in log-format. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 14f6b906d8..0a01e3c344 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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() : 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 | diff --git a/src/sample.c b/src/sample.c index bbb17d39fe..07c881dcf7 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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" */