zabbix监控nginx性能状态
ps: nginx在生产环境中的应用越来越广泛,所以需要对nginx的性能状态做一些监控来发现出来出现的问题。
zabbix监控nginx,首先确认nginx的监控指标,主要有:基本活动指标,错误指标,性能指标。
nginx处理流程图具体如下:
注释:Accepts(接受)、Handled(已处理)、Requests(请求数)是一直在增加的计数器。Active(活跃)、Waiting(等待)、Reading(读)、Writing(写)随着请求量而增减
名称 |
描述 |
|
Accepts(接受) |
NGINX 所接受的客户端连接数 |
资源: 功能 |
Handled(已处理) |
成功的客户端连接数 |
资源: 功能 |
Active(活跃) |
当前活跃的客户端连接数 |
资源: 功能 |
Dropped(已丢弃,计算得出) |
丢弃的连接数(接受 - 已处理) |
工作:错误* |
Requests(请求数) |
客户端请求数 |
工作:吞吐量 |
NGINX worker 进程接受 OS 的连接请求时 Accepts 计数器增加,而Handled 是当实际的请求得到连接时(通过建立一个新的连接或重新使用一个空闲的)。这两个计数器的值通常都是相同的,如果它们有差别则表明连接被Dropped, 往往这是由于资源限制,比如已经达到 NGINX 的worker_connections的限制。
首先nginx需要配置nginx_status 具体步骤是:在 zabbix agentd客户端上,查看nginx是否加载了with-http_stub_status_module。因为 zabbix 监控nginx是根据nginx的Stub Status模块,抓取Status模块所提供的数据。假如以前没开启,现在想启用StubStatus 模块,在编译nginx 的时候要加上参数with-http_stub_status_module,执行./configure && make就可以了,不用make install,一般情况下都是安装的,具体的安装配置如下
(一)配置nginx
1,查看nginx_status是否开启,查看已开启。
1 2 3 4 5 6 7 |
|
2,nginx_status开启的步骤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
3,测试并启动nginx
[root@iZ237lzm354Z scripts]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@iZ237lzm354Z scripts]# /usr/local/nginx/sbin/nginx -s reload
4,用curl来进行测试:
1 2 3 4 5 |
|
备注:
Active connections –当前活跃的连接数量
server accepts handled requests — 总共处理了756072922个连接 , 成功创建 756072922次握手, 总共处理了1136799890个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
(二)配置zabbix_agentd
1,编写脚步来获取nginx的相关信息
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
2,配置zabbix_agentd.conf。启用UserParameter,并配置相关的参数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
3,重启zabbix_agentd客户端
1 2 3 4 |
|
4,在zabbix服务端(server)进行测试。
1 2 3 |
|
(三)在网页上配置nginx模板的相关监控
1,登录zabbix界面,依次点击:配置(configuration)---模板(template)---导入(import)
2,给主机添加模板:选择主机---nginx服务器主机---模板---选择(刚刚导入的nginx性能状态的模板)---添加---更新
3,查看nginx监控的最新数据:监控中---图形---选择相应的监控类型。
备注:
Active :当前活跃的连接数。
Accepts: 接受的请求数
Handled: 处理的请求数(正常服务器响应,这两项应该是可以相等的)
Requests: 客户端处理的请求数。(吞吐量)
Reading: 当接收到请求时,连接离开 Waiting 状态,并且该请求本身使 Reading 状态计数增加。在这种状态下 NGINX 会读取客户端请求首部。请求首部是比较小的,因此这通常是一个快速的操作。
Writing: 请求被读取之后,其使 Writing 状态计数增加,并保持在该状态,直到响应返回给客户端。这意味着,该请求在 Writing 状态时, 一方面 NGINX 等待来自上游系统的结果(系统放在 NGINX “后面”),另外一方面,NGINX 也在同时响应。请求往往会在 Writing 状态花费大量的时间。
Waiting: 活跃的连接也可以处 于 Waiting 子状态,如果有在此刻没有活跃请求的话。新连接可以绕过这个状态并直接变为到 Reading 状态,最常见的是在使用“accept filter(接受过滤器)” 和 “deferred accept(延迟接受)”时,在这种情况下,NGINX 不会接收 worker 进程的通知,直到它具有足够的数据才开始响应。如果连接设置为 keep-alive ,那么它在发送响应后将处于等待状态
附nginx.xml
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-03-26T04:17:58Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template_Nginx</template>
<name>Template_Nginx</name>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<items>
<item>
<name>Nginx $1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[waiting,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[writing,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[active_connections,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[reading,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1/sec</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[handled_requests,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1/sec</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[accepted_connections,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Nginx $1/sec</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>nginx[handled_connections,{$NGINX_STATUS_URL}]</key>
<delay>60</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Nginx</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Number of $1 process</name>
<type>0</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>proc.num[nginx]</key>
<delay>300</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
</item>
</items>
<discovery_rules/>
<macros>
<macro>
<macro>{$NGINX_STATUS_URL}</macro>
<value>http://127.0.0.1:10061/nginx_status</value>
</macro>
</macros>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{Template_Nginx:proc.num[nginx].last(0)}=0</expression>
<name>Nginx is not running on {HOSTNAME}</name>
<url/>
<status>0</status>
<priority>4</priority>
<description>Nginx is not running.
It has been stopped / shutdown or has crashed.
Check on the server for more details:
- w / last
- dmesg logs
- /var/log/messages
- nginx error logs</description>
<type>0</type>
<dependencies/>
</trigger>
</triggers>
<graphs>
<graph>
<name>Nginx - Connections and Requests status</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>0</show_work_period>
<show_triggers>0</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>1</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>1</drawtype>
<color>FF9999</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[accepted_connections,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>2</drawtype>
<color>990000</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[handled_connections,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>009900</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[handled_requests,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
</graph_items>
</graph>
<graph>
<name>Nginx - Threads status</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>0</show_work_period>
<show_triggers>0</show_triggers>
<type>1</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>1</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>1</drawtype>
<color>990000</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[writing,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>1</drawtype>
<color>999900</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[reading,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>1</drawtype>
<color>009900</color>
<yaxisside>0</yaxisside>
<calc_fnc>4</calc_fnc>
<type>0</type>
<item>
<host>Template_Nginx</host>
<key>nginx[waiting,{$NGINX_STATUS_URL}]</key>
</item>
</graph_item>
</graph_items>
</graph>
</graphs>
</zabbix_export>