Amazon CloudFront Edges in AWStats

To follow up on a previous posts to get Amazon logs to AWStats, here is some additional information of how to get CloudFront edges to show up in the logs as well.

Amazon CloudFront Edges in AWStats
Johan Steen
by Johan Steen

Here's a quick breakdown of how to get the usage of your different Amazon CloudFront Edge locations within AWStats. I confess that I get some crazy pleasure from collecting statistics, still though, bandwidth usage is of interest in this case, as well as hits and that it can be interesting to see which regions most of the visitors come from.

I use the cluster functionality in AWStats to display the CloudFront Edges, as can be seen in the screenshot to the right.

I'm running AWStats on an Ubuntu server and this guide assumes that you are already collecting your CloudFront logs to a server and processes them with AWStats. If not, check out my other article dealing with that.

Let's work with our hypothetical CloudFront distribution named cdn.example.com.

In Ubuntu AWStats stores the configurations files in /etc/awstats/ so I will assume there is a file located there named

/etc/awstats/awstats.cdn.example.com.conf

which processes the CloudFront log already.

If you have configured the above .conf file properly for CloudFront, %cluster is collected in the LogFormat which contains all information needed to be able to display the edges. So now we only need to tell AWStats to start using that information.

First in the awstats.cdn.example.com.conf, enable cluster statistics by finding ShowClusterStats=0 and change it to:

ShowClusterStats=PHB

And then continue down to the plugin section and uncomment

LoadPlugin="clusterinfo"

Now we only need to tell AWStats the name of the edges, so they make sense when checking the statistics later on. In AWStats DirData directory, create a file named clusterinfo.[your AWStats config name].txt

Which in our example would be

/var/lib/awstats/clusterinfo.cdn.example.com.txt

This file shall contain a tab separated list of cluster numbers and then a text to display for each cluster. At the time of writing this article this is the complete list to paste into that file for all available CloudFront Edges. If Amazon adds more edges in the future they will have to be added at that time.

DFW3    USA: Dallas/Fort Worth, TX
EWR2    USA: Newark, NJ
IAD2    USA: Ashburn, VA
JAX1    USA: Jacksonville, FL
JFK1    USA: New York, NY
LAX1    USA: Los Angeles, CA
MIA3    USA: Miami, FL
SEA4    USA: Seattle, WA
SFO4    USA: Palo Alto, CA
STL2    USA: St. Louis, MO
AMS1    Europe: Amsterdam
DUB2    Europe: Dublin
FRA2    Europe: Frankfurt
LHR3    Europe: London
HKG1    Asia: Hong Kong
NRT4    Asia: Tokyo
SIN2    Asia: Singapore

Okay, that's it, the next time AWStats updates the statistics output you should start getting Edge usage outputted in the Cluster section, like in the screenshot above.

Discuss this article

The conversation has just started. Comments? Thoughts?

If you'd like to discuss any of the topics covered in this article, then head over and hang out on Discord.

You can also get in touch with me, and keep up with what I'm up to, on Twitter or Mastodon.

Sign up to the newsletter to get occasional emails about my game development.