Best Free Tools for Apache Tomcat Log Analysis: Usage Statistics Simplified


2 views

When working with Apache Tomcat server logs, many developers need a straightforward way to extract basic usage statistics without complex setup or real-time monitoring. The key requirements typically include:

  • Counting unique visitors by day/week/month
  • Basic traffic pattern analysis
  • Simple installation and operation
  • No enterprise-level features

Here are three effective tools that meet these needs:

1. GoAccess

This real-time web log analyzer works beautifully with Tomcat logs:


# Install on Ubuntu/Debian
sudo apt-get install goaccess

# Analyze Tomcat access log
goaccess /var/log/tomcat9/localhost_access_log.*.txt \
--log-format=COMBINED \
--output=report.html

2. AWStats

The classic log analyzer with solid Tomcat support:


# Sample AWStats configuration for Tomcat
LogFile="/var/log/tomcat/access_log.%YYYY-24%MM-24%DD-24.log"
LogFormat=4
SiteDomain="yourdomain.com"
HostAliases="localhost 127.0.0.1"

3. Analog

A lightweight alternative that's been around for decades:


# Sample analog configuration
LOGFILE /var/log/tomcat/localhost_access_log*.txt
HOSTNAME "My Tomcat Server"
OUTFILE ./tomcat_stats.html

For developers who prefer custom solutions, here's a simple Python script to count unique IPs:


import re
from collections import defaultdict

def analyze_tomcat_log(log_path):
    daily_counts = defaultdict(set)
    
    with open(log_path) as f:
        for line in f:
            # Extract IP and date from common Tomcat log format
            match = re.match(r'^(\d+\.\d+\.\d+\.\d+).*?\[(\d+/\w+/\d+)', line)
            if match:
                ip, date = match.groups()
                daily_counts[date].add(ip)
    
    for date, ips in sorted(daily_counts.items()):
        print(f"{date}: {len(ips)} unique visitors")

analyze_tomcat_log('/path/to/access_log.txt')

Consider these factors when selecting a solution:

Tool Pros Cons
GoAccess Real-time, modern interface Requires terminal access
AWStats Detailed reports, graphical More complex setup
Analog Lightweight, fast Basic visualization
Custom Script Fully customizable Requires coding

When working with Apache Tomcat servers, analyzing access logs is crucial for understanding user behavior and server performance. While there are many commercial solutions available, open-source tools can provide excellent functionality for basic usage statistics extraction.

Here are three practical options that handle Tomcat's standard access log format well:

  • GoAccess: Real-time terminal-based analyzer with HTML report generation
  • AWStats: Classic web analytics solution with detailed reporting
  • Log Parser Lizard: GUI tool for Windows with SQL-like query capabilities

For a command-line solution that's both powerful and simple to use, GoAccess stands out. Install it via package manager:

# Ubuntu/Debian
sudo apt-get install goaccess

# CentOS/RHEL
sudo yum install goaccess

Basic usage to analyze Tomcat logs:

goaccess /path/to/tomcat/logs/localhost_access_log.* \
--log-format=COMBINED \
--output=report.html

Tomcat's access logs typically follow the COMBINED format (like Apache), but if you've customized the pattern in server.xml, you may need to adjust:

# For custom patterns
goaccess access_log --log-format='%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"' \
--date-format=%d/%b/%Y \
--time-format=%T

For those preferring a web interface, AWStats can be configured for Tomcat:

# In awstats.yourdomain.conf
LogFile="/path/to/tomcat/logs/localhost_access_log.%YYYY-24%MM-24%DD-24"
LogFormat=1
SiteDomain="yourdomain.com"

Run the analysis:

perl awstats.pl -config=yourdomain -update

For quick command-line analysis without installing tools, you can use basic Unix commands:

# Unique IPs per day
cat localhost_access_log.* | awk '{print $4}' | cut -d: -f1 | uniq -c

# Requests by response code
cat localhost_access_log.* | awk '{print $9}' | sort | uniq -c | sort -rn

These methods give you immediate insights while keeping your toolchain lightweight.