Ahmed Gamal
Ahmed Gamal

Reputation: 96

Get Requests count per IP per request in Nginx access.log

I have unix server running nginx Debian GNU/Linux 9

I am trying to get requests count per IP per request in Nginx access.log file for analysis, so I have 2 questions:

  1. is there a unix command to fetch this info from the log file (the whole file), per ip per request?
  2. also is it possible to filter it by date?, i mean get the requests count per IP per request in a certain day. so hopefully i get something like this
IP        count
127.0.0.1 4
127.0.0.2 5
127.0.0.3 6

i found this, but it just counts ips

sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr

Upvotes: 3

Views: 11866

Answers (1)

NeverStopLearning
NeverStopLearning

Reputation: 63

Yes, you can use grep in the first command :

grep '12/Jan/2021' access.log | awk '{print $1}' | sort | uniq -c | sort -nr

and for certain date using extended regular expression :

grep -E '11/Jan/2021|12/Jan/2021' access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -20

Upvotes: 6

Related Questions