V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhengji
V2EX  ›  Lua

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

  •  1
     
  •   zhengji · 2016-01-08 19:56:55 +08:00 · 6394 次点击
    这是一个创建于 3002 天前的主题,其中的信息可能已经有所发展或是发生改变。

    实时监控 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
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5452 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:34 · PVG 09:34 · LAX 18:34 · JFK 21:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.