Sky17

nginx monitor about upstream

This project is maintained by wangfakang

nginx-ustats-module模块的研究与改进

一.安装与配置说明

    location /ustats {
        ustats memsize=3m; #指定监控共享内存饿大小.
        ustats_refresh_interval 6000;#监控数据多长时间刷新一次
        ustats_html_table_width 95;#html的宽度
        ustats_html_table_height 95;#html的高度
    }

二.实现原理

该模块主要的思想就是在nginx的upstream的处理的不同阶段来进行记录相应的peer的状态.值得学习的是:他使用了一个大的共享内存 完美的解决多个worker数据的聚合,当然多进程操作同一块共享内存存在安全问题,是这样解决的:使用nginx中封装的cpu原子操作来进行 计数(如:ngx_atomic_fetch_add).还有个技巧就是:使用一个大的共享内存,然后各自peer只需记住自己在共享内存中的起始地址,然后 使用其偏移量进行读取就ok了.

三.监控数据说明

The module's web interface provides a good visual representation of what's going on with your backends. Values in some columns of the table can be sorted within each upstream row.

Gathered data can also be retrieved in JSON format. To do so, append ?json=1 to the end of location on which the module was set to work on (see configuration instructions below).

{
    "bar":
    [
        ["127.0.0.1:80", 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 10, 1, "0000-00-00 00:00:00", "0000-00-00 00:00:00", 0],
        ["127.0.0.1:81", 0, 0, 1320, 3, 44, 0, 0, 0, 0, 1320, 0, 0, 1, 10, 1, "2016-01-21 15:18:19", "2016-01-21 15:19:19", 1853],
        ["61.135.169.125:80 (www.baidu.com)", 0, 0, 1476, 1, 160, 0, 0, 0, 0, 0, 2, 0, 1, 10, 1, "2016-01-21 15:18:19", "2016-01-21 15:19:19", 1942],
        ["61.135.169.121:80 (www.baidu.com)", 0, 0, 1498, 1, 18, 0, 0, 0, 0, 0, 0, 0, 1, 10, 1, "2016-01-21 15:18:19", "2016-01-21 15:18:48", 1947],
        0
    ],
    "www.baidu.com":
    [
        ["61.135.169.121:80 (www.baidu.com)", 0, 0, 687, 48, 861, 0, 0, 0, 0, 0, 0, 0, 1, 10, 1, "2016-01-21 15:19:38", "2016-01-21 15:19:46", 338],
        ["61.135.169.125:80 (www.baidu.com)", 0, 0, 683, 40, 793, 0, 0, 0, 0, 0, 0, 0, 1, 10, 1, "2016-01-21 15:19:38", "2016-01-21 15:19:47", 353],
        1
    ]
}

upstream name:
[
[peer_name, down, failed, requests, RPS, SPEED, 499, 5xx, 500, 503, tcp_errors, R_timeouts, w_timeouts, weight, f_t, m_f, s_t, last_fail_t, tot_f], implicit
]

implicit: means different upstream (if implicit 1 means 'implicit' upstream for example proxy_pass).

5xx: 499 < x < 600 explict 500 503

Screenshot

Communite

在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流

Thx

Author