Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Varnish 3.0.3 (9e6a70f) Time to Last Byte varnishncsa patch
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index ff07ed5..3af1367 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -98,6 +98,7 @@ static struct logline {
struct tm df_t; /* %t, Date and time */
char *df_u; /* %u, Remote user */
char *df_ttfb; /* Time to first byte */
+ char *df_ttlb; /* Time to last byte */
const char *df_hitmiss; /* Whether this is a hit or miss */
const char *df_handling; /* How the request was handled (hit/miss/pass/pipe) */
int active; /* Is log line in an active trans */
@@ -244,6 +245,7 @@ clean_logline(struct logline *lp)
freez(lp->df_s);
freez(lp->df_u);
freez(lp->df_ttfb);
+ freez(lp->df_ttlb);
VTAILQ_FOREACH_SAFE(h, &lp->req_headers, list, h2) {
VTAILQ_REMOVE(&lp->req_headers, h, list);
freez(h->key);
@@ -544,13 +546,16 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
case SLT_ReqEnd:
{
char ttfb[64];
+ char ttlb[64];
if (!lp->active)
break;
- if (lp->df_ttfb != NULL || sscanf(ptr, "%*u %*u.%*u %ld.%*u %*u.%*u %s", &l, ttfb) != 2) {
- clean_logline(lp);
- break;
+ if ((lp->df_ttfb != NULL || lp->df_ttlb != NULL)
+ || sscanf(ptr, "%*u %*u.%*u %ld.%*u %*u.%*u %63[0-9.] %63[0-9.]", &l, ttfb, ttlb) != 3) {
+ clean_logline(lp);
+ break;
}
lp->df_ttfb = strdup(ttfb);
+ lp->df_ttlb = strdup(ttlb);
t = l;
localtime_r(&t, &lp->df_t);
/* got it all */
@@ -759,6 +764,10 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
VSB_cat(os, lp->df_ttfb);
p = tmp;
break;
+ } else if (strcmp(fname, "Varnish:time_lastbyte") == 0) {
+ VSB_cat(os, lp->df_ttlb);
+ p = tmp;
+ break;
} else if (strcmp(fname, "Varnish:hitmiss") == 0) {
VSB_cat(os, (lp->df_hitmiss ? lp->df_hitmiss : "-"));
p = tmp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment