Skip to content

Instantly share code, notes, and snippets.

@jelder
Created July 28, 2010 12:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jelder/494265 to your computer and use it in GitHub Desktop.
Save jelder/494265 to your computer and use it in GitHub Desktop.
Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish.
/*
* Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish.
*
*/
#include <sys/time.h>
struct timeval detail_time;
gettimeofday(&detail_time,NULL);
char start[20];
sprintf(start, "t=%lu%06lu", detail_time.tv_sec, detail_time.tv_usec);
VRT_SetHdr(sp, HDR_REQ, "\020X-Request-Start:", start, vrt_magic_string_end);
@jelder
Copy link
Author

jelder commented Jul 28, 2010

Save to /etc/varnish/newrelic.h and add the following to your vcl_recv declaration in default.vcl.

C{
#include </etc/varnish/newrelic.h>
}C

@trivoallan
Copy link

This code does not seem to work anymore. Here's what varnish says :

# varnish_reload_vcl 
Loading vcl from /etc/varnish/default.vcl
Current running config name is reload_2012-06-14T15:46:25
Using new config name reload_2012-06-28T16:59:48
Message from C-compiler:
In file included from ./vcl.YttVe_cv.c:489:
/etc/varnish/newrelic.h: In function ‘VGC_function_vcl_recv’:
/etc/varnish/newrelic.h:9: erreur: ‘NULL’ undeclared (first use in this function)
/etc/varnish/newrelic.h:9: erreur: (Each undeclared identifier is reported only once
/etc/varnish/newrelic.h:9: erreur: for each function it appears in.)
/etc/varnish/newrelic.h:11: attention : implicit declaration of function ‘sprintf’
/etc/varnish/newrelic.h:11: attention : incompatible implicit declaration of built-in function ‘sprintf’
Running C-compiler failed, exit 1
VCL compilation failed
Command failed with error code 106

@jelder
Copy link
Author

jelder commented Jun 28, 2012

@trivollan I am not currently running Varnish or New Relic in production, but I'm sure the folks on the mailing list or IRC (#varnish on irc.linpro.no) can point out what's changed since I wrote this.

@trivoallan
Copy link

Thanks the fast answer. I'll go and see if i can find help there.

@nesquena
Copy link

@trivoallan Did you ever uncover the answer?

@Kalyse
Copy link

Kalyse commented Jan 20, 2013

If you are using Varnish 3.0 you need to place the C includes outside of the VCL blocks.


........
C{
    #include <syslog.h>
    #include <sys/time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
}C

sub vcl_recv {

    C{
        struct timeval detail_time;
        gettimeofday(&detail_time,NULL);
        char start[20];
        sprintf(start, "%lu%06lu", detail_time.tv_sec, detail_time.tv_usec);
        VRT_SetHdr(sp, HDR_REQ, "\020X-Request-Start:", start, vrt_magic_string_end);
    }C

........

sub vcl_deliver {
    set resp.http.X-ID = req.xid;
}
.......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment