NGINX Parser is a tool for analyzing NGINX log files. It simplifies working with logs by providing detailed statistics on requests, response sizes, HTTP codes, and other parameters. The program supports both local files (with wildcard patterns) and remote files via URL. The program processes data in a streaming mode without loading the entire file into memory. The analysis results are presented in convenient formats: Markdown or AsciiDoc.
The NGINX log format is:
$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"
.
- Counts the total number of requests.
- Identifies the most frequently requested resources.
- Counts the most common HTTP response codes.
- Counts the most common IP addresses.
- Calculates the average server response size.
- Computes the 95th percentile of response sizes.
- Calculates the average number of requests per day.
- Filters logs by time range (
from
andto
in ISO8601 format). - Supports output in Markdown or AsciiDoc format.
- Processes both local files (including patterns) and URLs.
- Supports filtering logs by specific values.
- Clone the repository:
git clone git@github.com:LLIEPJIOK/nginxparser.git
- Navigate to the repository folder:
cd nginxparser
- Run the program:
go run cmd/parser/main.go -p <path_to_logs> <additional_flags>
go run cmd/parser/main.go -p logs/*/* -filter-field Status -filter-value 404 -fmt adoc -o result.txt
==== General Information
[options="header"]
|===
| Metric | Value
| Files | logs/log1/logs.txt, logs/log2/logs.txt
| Number of requests | 552
| Average response size | 74
| 95th percentile of response size | 117
| Average requests per day | 552
|===
==== Requested Resources
[options="header"]
|===
| Resource | Count
| `/composite.svg` | 4
| `/24/7-encoding/systematic-grid-enabled.png` | 2
| `/24/7.js` | 2
|===
==== Response Codes
[options="header"]
|===
| Code | Name | Count
| 404 | Not Found | 552
|===
==== Requesting Addresses
[options="header"]
|===
| Address | Count
| 1.223.212.18 | 2
| 10.218.230.66 | 2
| 10.88.70.207 | 2
|===
-
Log Reading:
- Verify reading of local files and URLs.
- Test wildcard patterns for local file paths.
-
Log Parsing:
- Validate correct parsing of NGINX log lines.
-
Filtering:
- Test filtering records by time range.
- Test filtering by specific fields (e.g.,
GET
method orMozilla
user agent).
-
Statistics Calculation:
- Verify the accuracy of all computed metrics.
-
Output:
- Validate that the output meets Markdown and AsciiDoc format requirements.