[PATCH] Added %I and %O formatters to varnishncsa (byte counts)

David Robertson davidr at crane7.co.uk
Wed May 21 20:14:04 CEST 2014


This adds %I and %O formatters to varnishncsa, which are total bytes
received and total bytes sent from/to the client respectively. These
are similar to the same formatters in apache (with mod_logio). Useful
for bandwidth
accounting.

Thanks,
David.

---
 bin/varnishncsa/varnishncsa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 2162118..5aa0361 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -45,6 +45,8 @@
  * %b Length of reply body, or "-"
  * %{Referer}i Contents of "Referer" request header
  * %{User-agent}i Contents of "User-agent" request header
+ *  %I Total bytes recieved from client
+ *  %O Total bytes sent to client
  *
  * Actually, we cheat a little and replace "%r" with something close to
  * "%m http://%{Host}i%U%q %H", where the additional fields are:
@@ -95,6 +97,8 @@ enum e_frag {
  F_h, /* %h Host name / IP Address */
  F_m, /* %m Method */
  F_s, /* %s Status */
+ F_I, /* %I Bytes recieved */
+ F_O, /* %O Bytes sent */
  F_tstart, /* Time start */
  F_tend, /* Time end */
  F_ttfb, /* %{Varnish:time_firstbyte}x */
@@ -574,6 +578,12 @@ parse_format(const char *format)
  case 'U': /* URL */
  addf_fragment(&CTX.frag[F_U], "-");
  break;
+ case 'I': /* Bytes recieved */
+ addf_fragment(&CTX.frag[F_I], "-");
+ break;
+ case 'O': /* Bytes sent */
+ addf_fragment(&CTX.frag[F_O], "-");
+ break;
  case '{':
  p++;
  q = p;
@@ -783,6 +793,8 @@ dispatch_f(struct VSL_data *vsl, struct
VSL_transaction * const pt[],
  break;
  case SLT_ReqAcct:
  frag_fields(b, e, 5, &CTX.frag[F_b], 0, NULL);
+ frag_fields(b, e, 3, &CTX.frag[F_I], 0, NULL);
+ frag_fields(b, e, 6, &CTX.frag[F_O], 0, NULL);
  break;
  case SLT_Timestamp:
  if (isprefix(b, "Start:", e, &p)) {
--
1.9.1



More information about the varnish-dev mailing list