All about unix linux freebsd and FAQ for Packetlove.com Web hosting , Mail hosting , VoIP + IP PBX server > all application on unix knowledges by golfreeze

เพิ่ม response time ใน log ของ nginx

(1/1)

golfreeze:
ในกรณีต้องการเพิ่ม response time ใน log ของ nginx เพื่อ tracking request / response  สามารถทำได้ที่ไฟล์
 /etc/nginx/nginx.conf

เพิ่ม configure ข้างล่างนี้ใน หัวข้อ "http"
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '$request_time $upstream_response_time $pipe';

จากนั้นเพิ่มบันทัดของ access log
access_log /var/log/nginx/yourdomain.com.access.log timed_combined;

และทำการ restart nginx 1 รอบ
แล้วทำการ tracking nginx log access.log ดูจะเจอ "0.584 0.584" อยู่ข้างหลัง log นั่นคือ response time ในหน่วยวินาที (sec)

1.46.150.138 - - [03/Mar/2024:07:14:35 +0700] "POST /api/packetlovetracking.php HTTP/1.1" 200 146 "-" "PKL/1.2.5 (iPhone; iOS 17.3.1; Scale/3.00)" 0.584 0.584

นำร่อง

[0] ดัชนีข้อความ

Go to full version