Reyesoft
Published in

Reyesoft

Track and log slow nginx requests

Photo by Nareeta Martin on Unsplash

Sometimes, we need to find slowly response times on our server delivered by nginx from proxied servers like PHP, Node or Angular SSR. Some technologies used on Reyesoft projects.

First of all, we need to log all nginx access logs with their resepective request time. On nginx configuration you need to change access_log to:

log_format timed_combined  '$request_time $upstream_response_time'
' [$time_local]'
' "$request" $status $body_bytes_sent';
access_log /var/log/nginx/access.log timed_combined;

The previous code, do this on your access.log file

$ tail -f /var/log/nginx/access.log
0.002 0.000 [25/Feb/2022:19:06:29 +0000] "GET /1630-es2015.js HTTP/1.1" 200 4524
0.003 0.004 [25/Feb/2022:19:06:29 +0000] "GET /assets/landing-page.jpg HTTP/1.1" 200 814
1.765 1.764 . [25/Feb/2022:19:06:34 +0000] "GET /saldo/banco/ HTTP/1.1" 200 98333
0.007 0.008 . [25/Feb/2022:19:06:55 +0000] "GET /6997-es2015.f767960602ec613104db.js HTTP/1.1" 200 933

As you can see, GET /saldo/banco/ of our site of Intercambio de Saldo are taking a lot of time: 1.765 seconds.

But, we need to see and watch only slowly requests. Then we just need run this:

$ tail -f /var/log/nginx/access.log | awk '$1+0 >= 0.5'
1.765 1.764 . [25/Feb/2022:19:06:34 +0000] "GET /saldo/banco/ HTTP/1.1" 200 98333

🎉 Voalá!

--

--

--

Reyesoft, soluciones informáticas

Recommended from Medium

VueJS JWT Authentication

JavaScript Usage by Industry

Code Test: Removing Images [p5.js]

The basics as a frontend developer in 2019

Do you know how to resolve CORS issues in Angular ?

Do you know how to resolve CORS issues in Angular?

Typescript Mock… for real

Ember.js Loading substate templates

Execution Context Creation & Hoisting

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pablo Reyes

Pablo Reyes

Desarrollador Web. Emprendedor compulsivo. Apasionado por el cine, los viajes y la fotografía. CEO de SaldoAr y Reyesoft. Trato de no dejar nada a medi

More from Medium

Deploy to Kubernetes in 5 minutes with Docker Compose and Okteto Cloud

Running Redis with resilience in Linux containers on Windows — Part 2

docker network informational commands

Ackee Node.js Optimized GitLab CI Runners

Understanding Different Exchanges of RabbitMQ