I
I
Igor Petrov2020-11-24 22:01:40
Nginx
Igor Petrov, 2020-11-24 22:01:40

How to determine the number of requests per second on nginx?

Good day, you need to determine the number of requests per second of the nginx server through the console using the logs, since there are many virtual domains on one server, and determining through status does not make sense. There is a command tail -f /var/log/nginx/mydomain.ru.access.log | pv -lr -i 1 >/dev/null, but it shows everything in real time without stopping the process, but you need to get only 1 response in real time with the process stopping, I couldn’t find anything like that in the documentation for PV, please tell me , maybe there are other options for determining the number of requests, I would be very grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zohan1993, 2020-11-24
@daniks

cat /var/log/nginx/mydomain.ru.access.log | awk '{print $1}' | uniq -c | sort -rn

     34 "2020-11-24T10:44:19+00:00"
     21 "2020-11-24T10:36:11+00:00"
     21 "2020-11-24T10:29:59+00:00"

awk '{print $1}' - select only the time from the log (for example $time_iso8601 )
uniq -c - count the number of unique records, in fact the number of requests per second
sort -rn - sort the output

K
ky0, 2020-11-24
@ky0

Globally - this is done not through the console, but by some software of the appropriate direction - the same ELK, for example. It will index all your logs and show beautiful graphs - at least by the number of requests, at least by what.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question