A powerful command-line tool for analyzing NGINX access logs with support for multiple input sources and output formats.
- Multiple Input Sources - Local files, glob patterns, and remote URLs
- Comprehensive Statistics - Request counts, response sizes, status codes, and more
- Percentile Calculations - 95th percentile response size analysis
- Date Filtering - Filter logs by date range (ISO8601 format)
- Multiple Output Formats - JSON, Markdown, and AsciiDoc
- Memory Efficient - Stream-based processing for large files
- Smart Parsing - Handles malformed log entries gracefully
- Java 21 or higher
- Maven 3.9+
# Clone the repository
git clone https://github.com/yourusername/nginx-log-analyzer.git
cd nginx-log-analyzer
# Build the project
mvn clean package shade:shade -DskipTests
# The JAR file will be located at
ls target/hw3-logs-1.0.jarjava -jar nginx-log-analyzer.jar --path <source> --format <format> --output <file> [options]| Option | Short | Required | Description |
|---|---|---|---|
--path |
-p |
✅ | Path to log file(s). Supports local files, glob patterns, and URLs |
--format |
-f |
✅ | Output format: json, markdown, or adoc |
--output |
-o |
✅ | Output file path |
--from |
❌ | Start date filter (ISO8601 format) | |
--to |
❌ | End date filter (ISO8601 format) |
| Code | Description |
|---|---|
0 |
Success |
1 |
Unexpected error |
2 |
Invalid usage (wrong parameters, missing files, etc.) |
Structured output following a strict JSON schema, perfect for further processing.
{
"files": ["access.log"],
"totalRequestsCount": 51462,
"responseSizeInBytes": {
"average": 659.22,
"max": 1768.00,
"p95": 1100.50
},
"resources": [
{"resource": "/downloads/product_1", "totalRequestsCount": 30285}
],
"responseCodes": [
{"code": 200, "totalResponsesCount": 10234}
]
}Human-readable tables, ideal for documentation and reports.
#### General Information
| Metric | Value |
|:------------------------------|:-----------|
| Files | access.log |
| Total Requests | 51462 |
| Average Response Size | 659.22 B |Professional documentation format with rich formatting support.
---- General Information ----
Files: test.txt
Total Requests: 11
Average Response Size: 451.36b
Max Response Size: 3316.0b
95th Percentile Size: 1903.0b
---- Requested Resources ----
- /downloads/product_1: 8 requests
- /downloads/product_2: 3 requests
---- Status Codes ----
- 304: 6 responses
- 200: 3 responses
- 404: 2 responses| Statistic | Description |
|---|---|
| Total Requests | Total number of processed log entries |
| Average Response Size | Mean response body size in bytes |
| Max Response Size | Maximum response body size in bytes |
| 95th Percentile | 95% of responses are smaller than this value |
| Top Resources | Top 10 most frequently requested resources |
| Response Codes | Distribution of HTTP status codes |
| Requests per Date | Daily request distribution with percentages |
| Unique Protocols | List of unique protocols (HTTP/1.1, HTTP/2, etc.) |
java -jar nginx-log-analyzer.jar \
--path /var/log/nginx/access.log \
--format json \
--output report.jsonjava -jar nginx-log-analyzer.jar \
--path "logs/2024*.log" \
--format markdown \
--output report.mdjava -jar nginx-log-analyzer.jar \
--path https://example.com/logs/access.log \
--format adoc \
--output report.adjava -jar nginx-log-analyzer.jar \
--path access.log \
--format json \
--output report.json \
--from 2024-01-01 \
--to 2024-12-31java -jar nginx-log-analyzer.jar \
--path access.log \
--format markdown \
--output report.md \
--from 2024-06-01mvn clean verifymvn testmvn clean verify jacoco:report
# Open target/site/jacoco/index.htmlThe project maintains 50%+ code coverage with comprehensive tests for:
- Log parsing
- Statistics calculation
- Export formats
- Input validation
- Error handling
The analyzer supports standard NGINX combined log format:
$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"
93.180.71.3 - - [17/May/2015:08:05:32 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3"
| Technology | Purpose |
|---|---|
| Java 21 | Core language with modern features |
| Maven | Build and dependency management |
| Picocli | Command-line argument parsing |
| Jackson | JSON serialization |
| CommonMark | Markdown generation |
| Log4j2 | Logging framework |
| JUnit 5 | Unit testing |
| AssertJ | Fluent assertions |
This project is licensed under the MIT License - see the LICENSE file for details.