• Nginx log_format性能参数$request_time $upstream_response_time


    log_format是指存储日志的时候所采用的格式,可以在/etc/nginx//nginx.conf的http字段中设置

    默认配置如下:

      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
      access_log  /var/log/nginx/access.log  main;

    在分析性能过程,有时需要分析请求耗时,可以添加$request_time $upstream_response_time两个参数实现:

      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status"';
    
        access_log  /var/log/nginx/access.log  main;

    完整案例:

    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        map $http_upgrade $connection_upgrade {
            default upgrade;
            '' close;
        }
    
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" $upstream_addr  '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
        server_tokens off;
        add_header X-Frame-Options SAMEORIGIN;
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }

    具体参数解释如下:

  • 相关阅读:
    说说与线程相关的方法
    sleep()和yield()有什么区别?
    同步和异步有何异同,分别在什么情况下使用?
    如何保证多个线程同时启动?
    volatile关键字能否保证线程安全?
    使用对象的wait()方法需要注意什么?
    乐观锁与悲观锁是什么?
    Condition实现等待、唤醒
    LongAdder与AtomicLong有什么区别?
    介绍一下ForkJoinPool的使用
  • 原文地址:https://www.cnblogs.com/uestc2007/p/16020549.html
Copyright © 2020-2023  润新知