How to get nice stats from Fastly using Logentries

If you never heard of Fastly, go check it out: https://www.fastly.com

Quickly, what is Fastly? It’s a CDN powered by Varnish. It means that they have a bunch of Varnish servers scattered across the globe, each node being able to cache and deliver your web pages. Why is it useful? Let’s assume that my site is hosted in Montreal, Canada. Now consider a user coming from Sweden. When he requests a page from my website, his browser will sent request to Montreal, my server will need to process the request, do whatever database processing is required, render the page, and sent it back to Sweden. This might take a few hundred milliseconds.

Now what happens with Fastly? Check out the Fastly Network Map:

Source: https://www.fastly.com/network

The initial request will be sent to the Stockholm node, which will request the page to our server and cache it locally. Once the page is cached, the Stockholm node will be able to deliver the cached page without the required trip to Canada, and the required processing by my server. It’s a lot faster.

Ok now, what does Logentries come into play? Logentries is log management software, has a free plan, and is supported by Fastly. So here’s what you need to do:

I will assume that you know the basics about Fastly and Logentries. Then follow these steps:

  1. If you didn’t already, send an email to Fastly support and ask them to enable custom VCL
  2. Create a new Log set in Logentries, take note of the token, and install theFastly Community Pack
  3. Create a new Logging entry point in Fastly (the name is important, we’ll need it later) 
  4. Grab the VCL provided by Logentries: https://community.logentries.com/wp-content/uploads/2015/04/le-fastly-pack-sample-VCL.vcl, replace ACCOUNT_KEY with your Fastly service ID, and make sure that the log name (LE) match the one in 3.
  5. Upload the VCL publish the configuration

Now you should receive logs in Logentries with a nice format. Problem is: you receive the logs twice, with 2 different formats. Why is that? When you create a new Logging endpoint, it will send logs to Logentries with the default Fastly format. And we now send a custom log format with our modified VCL. To fix this annoying issue, we need to silent the default log. This can be done by adding a conditions that’s always false:

Voila! Now you have awesome (and unique) logs and analytics in your Logentries account.

Leave a Reply

Your email address will not be published. Required fields are marked *