zhengji
V2EX  ›  Lua

ngx_lua_reqstatus 实时监控 Nginx 域名 qps 的 lua 拓展

  •  1
     
  •   zhengji · Jan 8, 2016 · 7460 views
    This topic created in 3801 days ago, the information mentioned may be changed or developed.

    实时监控 Nginx 域名的 qps, 5xx 个数,响应时长 GitHub

    配置

    # nginx.conf
    http {
        ...
        ...
    
        lua_shared_dict statics_dict    1M; # 初始化变量
        lua_package_path "/etc/nginx/ngx_lua_reqstatus/?.lua";  #路径
        log_by_lua_file "/etc/nginx/ngx_lua_reqstatus/hook.lua"; # 添加此句
    
        server {
            listen 80;
            server_name  www.justforfun.com; 
    
            location /{
                ...
            }
        }
    
        # http 接口
        server {
            listen 127.0.0.1:6080;
            location /{
                access_by_lua_file "/etc/nginx/ngx_lua_reqstatus/status.lua";
            }
        }
    }
    

    效果

    查看 www.justforfun.com 的运行状况:

    curl localhost:6080/?domain=www.justforfun.com
    

    输出

    Server Name key:    www.justforfun.com
    Seconds SinceLast:  26.601999998093
    Average Req Time Sec:   0.031799983978271
    Request Count:  5
    Requests Per Secs:  0.18795579281101
    5xx num:    0
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2716 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:54 · PVG 12:54 · LAX 21:54 · JFK 00:54
    ♥ Do have faith in what you're doing.