IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    实时监控 nginx qps 的拓展

    zheng-ji发表于 2016-01-07 12:59:00
    love 0

    用下班时间写了一个 ngx lua 的拓展, GitHub。可以:

    • [x] 实时监控域名的 qps
    • [x] 实时监控域名的 5xx 个数
    • [x] 实时监控域名的 响应时长
    • [x] 并附带 Ganglia 监控插件

    使用

    • 配置 nginx.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    http {
        ...
        ...
    
        lua_shared_dict statics_dict    1M; # 初始化变量
        lua_package_path "/etc/nginx/ngx_reqstatus_lua/?.lua";  #路径
    
        server {
            listen 80;
            server_name  justforfun.com; 
    
            # 在需要监控的 server_name 添加此句
            log_by_lua_file "/etc/nginx/ngx_reqstatus_lua/hook.lua";
            location /{
                ...
                ...
            }
        }
        # 监控服务
        server {
            listen 127.0.0.1:6080;
            location /{
                access_by_lua_file "/etc/nginx/ngx_reqstatus_lua/status.lua";
            }
        }
    }
    • 效果, 查看 justforfun.com 的命令
    1
    
    curl localhost:6080/?domain=justforfun.com
    • 输出
    1
    2
    3
    4
    5
    6
    
    Server Name:    justforfun.com
    Seconds SinceLast:   1.4399998188019 secs
    Request Count:      1
    Average Req Time:   0 secs
    Requests Per Secs:  0.69444453182781
    5xx num:    0


沪ICP备19023445号-2号
友情链接