Skip to content

TheOneOh1/Nginx-Log-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Nginx Log Analyzer

A simple yet powerful bash script to analyze Nginx access logs and provide insights about traffic patterns, response codes, and most requested paths.

Features

The script provides three main types of analysis:

  1. Top IP addresses making the most requests
  2. Most frequent HTTP response status codes
  3. Most requested URL paths

Requirements

  • Bash shell environment
  • Nginx access logs (named nginx-logs.txt in the same directory as the script)
  • Basic Unix tools: awk, sort, uniq, grep

Installation

  1. Clone or download the repository
  2. Make the script executable:
    chmod +x nginx-analyzer.sh

Usage

  1. Ensure your Nginx access log file is named nginx-logs.txt and is in the same directory as the script
  2. Run the script:
    ./nginx-analyzer.sh
  3. When prompted, enter the number of top results you want to see

Output Format

The script generates three sections of output:

1. Top IPs

Shows the IP addresses that made the most requests:

IP - [IP_ADDRESS] - [NUMBER] times

2. Top Response Codes

Displays the most frequent HTTP response status codes:

Code - [STATUS_CODE] - [NUMBER] requests

3. Top Requested Paths

Lists the most frequently requested URL paths:

Path - [URL_PATH] - [NUMBER] requests

Example

$ ./nginx-analyzer.sh
Show Top: 3
----- Top 3 IPs with the most requests -----
IP - 192.168.1.100 - 150 times
IP - 10.0.0.1 - 120 times
IP - 172.16.0.50 - 90 times

----- Top 3 response status codes -----
Code - 200 - 400 requests
Code - 404 - 50 requests
Code - 500 - 10 requests

----- Top 3 most requested paths -----
Path - /index.html - 200 requests
Path - /api/users - 150 requests
Path - /images/logo.png - 100 requests

Notes

  • The script assumes the Nginx log file follows the default Nginx log format
  • The log file must be named nginx-logs.txt and be in the same directory as the script
  • Make sure you have the necessary permissions to read the log file

About

A simple tool to analyze logs from the command line.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages