[黑鸟-Nginx] 使用黑鸟监控Nginx

黑鸟 Nginx 插件

使用此插件可以从nginx获取各种信息,并将数据发送到后端。
目前,您可以监视以下信息:

    • nginx の version (nginx -v)

 

    • stub_status の各項目

 

    特定 url に対する responce check (HTTP status code / Reponse Time)

安装

乌鸦的实质

请根据此作为参考进行安装。

安装nginx插件

可以通过setup.py安装方法和rpm安装方法来安装。
您也可以手动安装,但请确保单独安装了Python的requests模块。

使用setup.py进行安装

git clone https://github.com/Vagrants/blackbird-nginx.git
cd blackbird-nginx
python setup.py install

通过rpm安装

yum install blackbird-nginx--enablerepo=blackbird

在依赖关系中需要使用python-requests库。

使得Nginx能够获取状态。

定义stub_status。

server {
    listen 80;
    server_name localhost;
    location /nginx_status {
        stub_status on;
        access_log  off;
        allow 127.0.0.1;
        deny  all;
    }
}

假设我们以这种方式进行。

进行插件设置

配置位于/etc/blackbird/conf.d/nginx.cfg中。

[nginx]
module = 'nginx'

# stub_status URI
# - support only http status code '200'
# - you must set uri value start with '/'
#
status_uri = '/nginx_status'
# host = '127.0.0.1'
# port = '80'

# use ssl connection?
#
# ssl = False

# for BASIC authentication. default: Nothing
#
# user = 'nobody'

# for BASIC authentication. default: Nothing
#
# password = 'nobody'

# for response time check
# if you do not want to check, please comment out
# - support only http status code '200'
# - you must set uri value start with '/'
#
response_check_uri = '/'
# response_check_port = '80'
# response_check_host = '127.0.0.1'
# response_check_vhost = 'localhost'
# response_check_uagent = 'blackbird response check'
# response_check_ssl = False

# nginx path
path = '/usr/sbin/nginx'

如果指定了response_check_uri,将对该uri执行HTTP GET请求,然后测量HTTP的状态码和响应时间。同时,设置虚拟主机也可以监控服务用途的虚拟主机的响应。

設定完成後,重新啟動 blackbird。

sudo /etc/init.d/blackbird restart

确认在Zabbix上是否收到数据。

Zabbix的模板存放在GitHub的代码库中,请导入到Zabbix并应用于目标服务器。

如果Zabbix上的主机名与正在运行的Blackbird服务器的主机名不同,需要在/etc/blackbird/conf.d/nginx.cfg上设置主机名来与Zabbix配合。

hostname = your_static_hostname

此外,您还可以更改监视时间间隔(默认为60秒)。

interval = 30

关于Zabbix Template的项目

_Nginx_1.4_ :Nginx的1.4版

ApplicationitemdescriptionNginx – StatsStats – Acceptsstub_status の AcceptsNginx – StatsStats – Accepts cps上記の Connection Per SecNginx – StatsStats – Handledstub_status の HandledNginx – StatsStats – Handled cps上記の Connection Per SecNginx – StatsStats – Requestsstub_status の RequestsNginx – StatsStats – Requests cps上記の Connection Per SecNginx – StatsStats – Readingstub_status の ReadingNginx – StatsStats – Writingstub_status の WritingNginx – StatsStats – Waitingstub_status の WaitingNginx – PerformancePerformance – Amountaggregate 用 itemNginx – PerformancePerformance – Availableaggregate 用 itemNginx – PerformancePerformance – Response statusresponse_check_uri の HTTP statusNginx – PerformancePerformance – Response Timeresponse_check_uri の Response TimeVersionVersion – Nginxnginx の versionGeneralGeneral – Blackbird nginx plugin is sending datablackbird からの pingGeneralGeneral – Blackbird nginx plugin versionnginx plugin の versionGeneralGeneral – Port $PORT is in LISTENING state特定 port が Listen しているかGeneralGeneral – Port $PORT is accepting connections特定 port が Accept しているかGeneralProcess – Number of nginx processesnginx の process 数Macro{$ITM_NGINX_MONITOR_URI}アイテム表示用 (nginx.cfg と合わせて下さい)Macro{$ITM_NGINX_MONITOR_VHOST}アイテム表示用 (nginx.cfg と合わせて下さい)Macro{$ITM_NGINX_PORT}nginx の portMacro{$TRG_BBD_NGX_NDT_PRD}blackbird からの ping の間隔の閾値Macro{$TRG_NGINX_RSP_TIME}Response Time の閾値
关于{$TRG_BBD_NGX_NDT_PRD}

如果检测到黑鸟掉线,当一定时间间隔内未更新 ping 项目时,将触发触发器。这是该时间间隔的阈值。如果在 /etc/blackbird/conf.d/nginx.cfg 中增加了间隔,则也请增加此值。

关于 {$TRG_NGINX_RSP_TIME}

如果响应时间超过固定的秒数,触发器就会被激活。
这个阈值就是响应时间。
(模板中设置了当阈值连续超过3次时触发器被激活,但请根据实际情况做相应调整。)

这个模板的名字是 Nginx 1.4,但在1.6版本中也可以使用。

Nginx组监控

ApplicationitemdescriptionNginx – GroupGroup – Total serversgroup 監視のサーバー全体数Nginx – GroupGroup – Available serversgroup 監視のサーバーのうち正常な数Nginx – GroupGroup – Available servers rateその割合Macro{$ITM_NGINX_GROUP_NAME}group 監視する host groupMacro{$TRG_NGINX_AVAILABLE_RATE}Trigger の閾値

这个 _Nginx_group_monitor 是用来监控负载均衡下的服务器群中有多少个正常运行的服务器的,比如在由10台服务器构成的负载均衡集群中,可以检测到有一半的服务器返回的HTTP状态码不是200。
由于使用了Zabbix的Aggregate功能,所以需要将希望监控的服务器们放置在同一个主机组中进行管理。
顺便说一下,应用这个模板的服务器其实可以是任意的(比如127.0.0.1),但为了方便理解,建议在Zabbix上定义一个用于负载均衡的vip 主机,并将此模板应用于该主机上。

bannerAds