Difference between revisions of "Track HTTP Application Response time in Nginx"
Jump to navigation
Jump to search
↑ https://lincolnloop.com/blog/tracking-application-response-time-nginx/
↑ https://stackoverflow.com/a/39260524
(18 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<ref>https://lincolnloop.com/blog/tracking-application-response-time-nginx/</ref> | <ref>https://lincolnloop.com/blog/tracking-application-response-time-nginx/</ref> | ||
− | 1) Add to <code>/etc/nginx/[[nginx.conf]]</code> http://nginx.org/en/docs/http/ngx_http_log_module.html | + | 1) Add to <code>/etc/nginx/[[nginx.conf]]</code> befor your <code>[[access_log]]</code> directive http://nginx.org/en/docs/http/ngx_http_log_module.html |
<pre> | <pre> | ||
Line 7: | Line 7: | ||
'"$request" $status $body_bytes_sent ' | '"$request" $status $body_bytes_sent ' | ||
'"$http_referer" "$http_user_agent" ' | '"$http_referer" "$http_user_agent" ' | ||
− | '$ | + | '$pipe $upstream_response_time $request_time'; |
</pre> | </pre> | ||
− | 2) Modify <code>access_log</code> directive to use new format: | + | 2) Modify <code>[[access_log]]</code> directive to use new format: |
<pre> | <pre> | ||
access_log /var/log/nginx/yourdomain.com.access.log timed_combined; | access_log /var/log/nginx/yourdomain.com.access.log timed_combined; | ||
Line 20: | Line 20: | ||
− | 3) Check your new log format: | + | 3) Reload nginx: |
+ | [[nginx -t]] && [[systemctl restart]] nginx | ||
+ | |||
+ | 4) Check your new log format, last field contains (<code>$request_time</code>): | ||
[[tail]] -f /var/log/nginx/[[access.log]] | [[tail]] -f /var/log/nginx/[[access.log]] | ||
+ | |||
+ | == Related == | ||
+ | * Print http response times and date: | ||
+ | :<code>cat [[/var/log/nginx/access.log]] | awk '{print $4, $([[NF-1]])}'</code> | ||
+ | |||
+ | Print only if http response time exceed a threshold: | ||
+ | :<code>cat /var/log/nginx/access.log | awk '$(NF-1) > "0.300" {print $4, $(NF-1)}</code> | ||
+ | |||
+ | Web site [[response time]]: | ||
+ | * <code>[[curl -so]] /dev/null -w '%{time_total}\n' https://google.com</code> | ||
== See also == | == See also == | ||
* {{Nginx}} | * {{Nginx}} | ||
+ | |||
+ | |||
+ | [[Category:Nginx]] |
Latest revision as of 07:47, 9 May 2023
1) Add to /etc/nginx/nginx.conf
befor your access_log
directive http://nginx.org/en/docs/http/ngx_http_log_module.html
log_format timed_combined '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' '$pipe $upstream_response_time $request_time';
2) Modify access_log
directive to use new format:
access_log /var/log/nginx/yourdomain.com.access.log timed_combined;
request_time
This shows how long Nginx dealt with the requestupstream_response_time
Gives us the time it took our upstream server (in this case Apache/mod_wsgi) to respondpipe
Shows ‘p’ in case the request was pipelined.
3) Reload nginx:
nginx -t && systemctl restart nginx
4) Check your new log format, last field contains ($request_time
):
tail -f /var/log/nginx/access.log
Related[edit]
- Print http response times and date:
cat /var/log/nginx/access.log | awk '{print $4, $(NF-1)}'
Print only if http response time exceed a threshold:
cat /var/log/nginx/access.log | awk '$(NF-1) > "0.300" {print $4, $(NF-1)}
Web site response time:
curl -so /dev/null -w '%{time_total}\n' https://google.com
See also[edit]
- Web server: Nginx:
/etc/nginx/nginx.conf
,nginx -t
, Nginx logs, Nginx change log, PHP,php-fpm
, Let's encrypt, Nginx directives, Reverse Proxy, Configure HTTP redirection Nginx, Return,proxy_pass (Reverse proxy)
,ngx_http_rewrite_module
,/etc/nginx/sites-enabled/
,error.log
,access.log
,/nginx status
, AIO
Advertising: