Commit 9e6b75dc authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add %D and %T support to varnishncsa

parent 763a8117
...@@ -97,9 +97,11 @@ static struct logline { ...@@ -97,9 +97,11 @@ static struct logline {
char *df_h; /* %h (host name / IP adress)*/ char *df_h; /* %h (host name / IP adress)*/
char *df_m; /* %m, Request method*/ char *df_m; /* %m, Request method*/
char *df_s; /* %s, Status */ char *df_s; /* %s, Status */
struct tm df_t; /* %t, Date and time */ struct tm df_t; /* %t, Date and time, received */
char *df_u; /* %u, Remote user */ char *df_u; /* %u, Remote user */
char *df_ttfb; /* Time to first byte */ char *df_ttfb; /* Time to first byte */
double df_D; /* %D, time taken to serve the request,
in microseconds, also used for %T */
const char *df_hitmiss; /* Whether this is a hit or miss */ const char *df_hitmiss; /* Whether this is a hit or miss */
const char *df_handling; /* How the request was handled const char *df_handling; /* How the request was handled
(hit/miss/pass/pipe) */ (hit/miss/pass/pipe) */
...@@ -400,7 +402,6 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, ...@@ -400,7 +402,6 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
const char *ptr, unsigned len) const char *ptr, unsigned len)
{ {
const char *end, *next, *split; const char *end, *next, *split;
long l;
time_t t; time_t t;
assert(spec & VSL_S_CLIENT); assert(spec & VSL_S_CLIENT);
...@@ -557,18 +558,20 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, ...@@ -557,18 +558,20 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
case SLT_ReqEnd: case SLT_ReqEnd:
{ {
char ttfb[64]; char ttfb[64];
double t_start, t_end;
if (!lp->active) if (!lp->active)
break; break;
if (lp->df_ttfb != NULL || if (lp->df_ttfb != NULL ||
sscanf(ptr, "%*u %*u.%*u %ld.%*u %*u.%*u %s", &l, ttfb) sscanf(ptr, "%*u %lf %lf %*u.%*u %s", &t_start, &t_end, ttfb)
!= 2) { != 3) {
clean_logline(lp); clean_logline(lp);
break; break;
} }
if (lp->df_ttfb != NULL) if (lp->df_ttfb != NULL)
free(lp->df_ttfb); free(lp->df_ttfb);
lp->df_ttfb = strdup(ttfb); lp->df_ttfb = strdup(ttfb);
t = l; lp->df_D = t_end - t_start;
t = t_start;
localtime_r(&t, &lp->df_t); localtime_r(&t, &lp->df_t);
/* got it all */ /* got it all */
lp->complete = 1; lp->complete = 1;
...@@ -669,6 +672,10 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd, ...@@ -669,6 +672,10 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
VSB_cat(os, lp->df_b ? lp->df_b : "-"); VSB_cat(os, lp->df_b ? lp->df_b : "-");
break; break;
case 'D':
/* %D */
VSB_printf(os, "%f", lp->df_D);
case 'H': case 'H':
VSB_cat(os, lp->df_H ? lp->df_H : "HTTP/1.0"); VSB_cat(os, lp->df_H ? lp->df_H : "HTTP/1.0");
break; break;
...@@ -724,6 +731,11 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd, ...@@ -724,6 +731,11 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
VSB_cat(os, tbuf); VSB_cat(os, tbuf);
break; break;
case 'T':
/* %T */
VSB_printf(os, "%d", (int)lp->df_D);
break;
case 'U': case 'U':
VSB_cat(os, lp->df_U ? lp->df_U : "-"); VSB_cat(os, lp->df_U ? lp->df_U : "-");
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment