The amount of traffic your server receives is an important metric that any system administrator can observe. There are tools available that will show you easy-to-read graphics created with your web server̵
Use your log files
Every time someone accesses your web server, a new line entry is created in your web server’s access log. As a rule, the IP address of the client and the request made by it, as well as the response code, the date and time of access and other information about the request are logged.
Manually browsing the log files would be a hassle, but there is software out there that can use your log files to monitor the health of your server in real time. GoAccess is a popular open source tool for this use case. It can run in a terminal and will show useful statistics based on your log entries. It can keep track of the total number of visits per day and see which pages have the most traffic.
GoAccess also provides a web interface if you’d prefer to access it that way. This interface offers much more detailed information as well as real-time graphs that track every single visit. Visitors with the same IP, the same date and the same agent can be grouped into unique visitors.
GoAccess is completely free and open source. It is intended to be used for a single web server. If you have multiple web servers, consider a log management tool. Otherwise, multiple instances of GoAccess will be running on each server.
Alternatively, you can use a command like
apachetopor Nginx’s status module if you just want to know how much traffic you’re getting. If you are concerned about the CPU or memory usage of your web servers, you can monitor this with Monit, another open source tool.
You can install GoAccess through your distribution’s package manager. For Debian-based systems like Ubuntu that would be:
apt-get install goaccess
You can also download from source and compile if you want.
Next, you want to find your web server’s primary access log. This is usually in
/var/log/. For Apache it should be
/var/log/apache2/access.logand for Nginx it should be
/var/log/nginx/access.log. You can use
tail to preview the ends of these log files.
Then you want to run GoAccess and pass in the location of the log file:
You will be asked to choose a log file format. Common Log Format should work for Apache and Nginx.
You can then view your access statistics from the command line.
If you want to use the real-time web interface, you can run it with the following command:
goaccess /var/log/nginx/access.log -o /var/www/html/report.html --log-format=COMMON --real-time-html
This outputs an HTML page and runs a WebSocket server from which updates are received. You may want to put this page behind basic authentication, but your web server can access it from anywhere if you put it in your document root (usually)
If you want more data, install an Analytics Suite
Log files are great, but they can’t tell you everything. They are best used when you need accurate, real-time reports on both incoming and outgoing raw traffic. When you have a second for more data, you can use an analytics suite.
You probably want to install Google Analytics anyway because it’s completely free to use. You just add the
Tag in the header of your website and every visit to your website will be reported back to Google. It provides easy page view, bounce rate, and session tracking, along with demographic information and detailed summaries of how users use your website.
Google Analytics also supports basic A / B testing, which can help you improve the design of your website and achieve your goals more often.