Zabbix监控nginx性能的另外一种方式

nginx和php-fpm一样内建了一个状态页,对于想了解nginx的状态以及监控nginx非常有用,为了后续的zabbix监控,我们需要先启用nginx状态页

1. 启用nginx status配置
在默认主机里面加上location或者你希望能访问到的主机里面。

server {
    location /ngx_status
    {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}

2. 重载nginx

# nginx -t
# service nginx reload

3. 打开status页面

# curl 127.0.0.1:8555/ngx_status
Active connections: 2
server accepts handled requests
3091 3091 3254
Reading: 0 Writing: 1 Waiting: 1

# curl 127.0.0.1:8555/ngx_status
Active connections: 2
server accepts handled requests
3092 3092 3255
Reading: 0 Writing: 1 Waiting: 1

4. nginx status详解

active connections – 活跃的连接数量
server accepts handled requests — 总共处理了11989个连接 , 成功创建11989次握手, 总共处理了11991个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

以上为nginx性能计数,我们除了监控以上数据,还需要监控nginx进程状态,并且配置触发器
zabbix客户端配置

编写客户端脚本nginx_status.sh

# 检测nginx性能

mkdir -p /usr/local/zabbix-agent/scripts
vim /usr/local/zabbix-agent/scripts/nginx_status.sh
function active {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘
}
function reading {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘
}
function writing {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘
}
function waiting {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘
}
function accepts {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘
}
function handled {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘
}
function requests {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘
}
# 执行function
$1

添加脚本执行权限

# chmod +x /usr/local/zabbix-agent/scripts/nginx_status.sh

zabbix客户端配置
将自定义的UserParameter加入配置文件,然后重启agentd,如下:

# vim /etc/zabbix/zabbix_agentd.conf

UserParameter=nginx.status[*],/usr/local/zabbix-agent/scripts/nginx_status.sh $1

重启zabbix-agent
/etc/init.d/zabbix-agent restart

zabbix_get获取数据

此步骤可以跳过,但是最好是测试一下,因为通过此命令我们可以检测配置是否正确

# zabbix_get -s ip -p 10050 -k ‘nginx.status[accepts]‘
3101
# zabbix_get -s ip -p 10050 -k ‘nginx.status[ping]‘
1

zabbix web端配置

导入Template App NGINX模板

Link NGINX模板
到了最后一个阶段,登陆zabbix管理端,link模板到nginx服务器:configuration->hosts->点击nginx所在服务器->点击template->Link new templates输入"Template App NGINX"->Add->最后点击update
监控效果

监控模板:zbx3_export_templates.xml

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>3.0</version>
    <date>2017-07-17T09:37:18Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>Template nginx status</template>
            <name>Template nginx status</name>
            <description>nginx监控模板</description>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>nginx</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>nginx status server accepts</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[accepts]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>1</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>accepts</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status connections active</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[active]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>active</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status server handled</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[handled]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>1</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>handled</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status PING</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[ping]</key>
                    <delay>60</delay>
                    <history>30</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>is live</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap>
                        <name>Service state</name>
                    </valuemap>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status connections reading</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[reading]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>reading</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status server requests</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[requests]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>1</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>requests</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status connections waiting</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[waiting]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>waiting</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>nginx status connections writing</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>nginx.status[writing]</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>writing</description>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>nginx</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
            </items>
            <discovery_rules/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{Template nginx status:nginx.status[ping].last(0)}=0 and {Template nginx status:nginx.status[ping].last(1)}=0</expression>
            <name>nginx is down!</name>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <dependencies/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>nginx status</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</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>0</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>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[active]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[reading]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[waiting]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[writing]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>4</sortorder>
                    <drawtype>0</drawtype>
                    <color>FC6EA3</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[accepts]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>5</sortorder>
                    <drawtype>0</drawtype>
                    <color>6C59DC</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[handled]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>6</sortorder>
                    <drawtype>0</drawtype>
                    <color>AC8C14</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template nginx status</host>
                        <key>nginx.status[requests]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
    <value_maps>
        <value_map>
            <name>Service state</name>
            <mappings>
                <mapping>
                    <value>0</value>
                    <newvalue>Down</newvalue>
                </mapping>
                <mapping>
                    <value>1</value>
                    <newvalue>Up</newvalue>
                </mapping>
            </mappings>
        </value_map>
    </value_maps>
</zabbix_export>
时间: 2024-07-29 05:50:34

Zabbix监控nginx性能的另外一种方式的相关文章

zabbix监控nginx性能状态

nginx在生产环境中的应用越来越广泛,所以需要对nginx的性能状态做一些监控,来发现出来出现的问题.nginx处理流程图具体如下: 注释:Accepts(接受).Handled(已处理).Requests(请求数)是一直在增加的计数器.Active(活跃).Waiting(等待).Reading(读).Writing(写)随着请求量而增减 名称 描述 指标类型 Accepts(接受) NGINX 所接受的客户端连接数 资源: 功能 Handled(已处理) 成功的客户端连接数 资源: 功能

zabbix 监控 nginx性能

http://www.ttlsa.com/nginx/nginx-status-detail/ http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/ 首先需要配置ngx_status vim /etc/nginx/vhost/web.conf server { listen       80; server_name 192.168.80.62; index index.php index.html index.htm def

zabbix管理七之监控nginx性能

说明: 使用zabbix监控nginx,首先nginx需要配置ngx_status 在编译安装nginx时需要使用--with-http_stub_status_module参数 在nginx的配置文件nginx.conf里添加如下:         location /nginx_status {              stub_status on;              access_log off;              allow 127.0.0.1;            

Zabbix监控nginx服务进程状态

zabbix监控nginx需要开启nginx status,要确认nginx编译http_sub_module模块! 1.检查当前nginx是否安装配置http_sub_module模块 # nginx -V Tengine version: Tengine/1.5.2 (nginx/1.2.9) built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: --p

zabbix如何监控nginx性能

环境:zabbix server :centos 6  ip 192.168.234.134 zabbix client (nginx) :centos 7  ip:192.168.234.133 前提: 在zabbix agentd客户端上,查看nginx是否加载了--with-http_stub_status_module.因为zabbix监控nginx是根据nginx的Stub Status模块,抓取Status模块所提供的数据.假如以前没开启,现在想启用StubStatus 模块,在编译

Zabbix 监控 Nginx 状态

1.获取 Nginx 状态条件( 需要nginx安装模块) [localhost]#/usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.0built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_sta

zabbix监控nginx

上一篇介绍了zabbix安装,这里接着说说zabbix监控nginx 安装zabbix-agent 在实际应用中,我们server和agent部在同一机器上,所以需要分开安装,其实上一篇已经说了,在编译安装zabbix-server的时候也安装了zabbix-agent,如果只安装zabbix-agent # 切换到zabbix解压目录 cd zabbix-3.0.3 # 编译配置 ./configure --prefix=/usr/local/zabbix-agent --enable-age

利用Zabbix监控Web性能和可用性

怎么利用Zabbix监控web性能和可用性呢? 我们这边分为几个步骤:打开网站.登陆.登陆验证.退出,一共4个小step,看实例. 检测流程 1. 打开网站:如果http code为200,并且响应的html中包含Zabbix SIA表示打开成功(zabbix页面有这个标示) 2. 登陆后台:post用户名和密码到index.php,如果响应200,那表示post成功.并且通过正则表达式从响应的html中匹配sid,这个sid也就是一个宏变量,退出可以使用到 3. 验证登陆:打开首页,检索htm

zabbix监控nginx连接状态

zabbix学习笔记:zabbix监控nginx连接状态 zabbix监控nginx zabbix可以监控nginx的状态,关于一个服务的状态可以查看服务本身的状态(版本号.是否开启),还应该关注服务能力(例如以nginx的负载效果:连接数.请求数和句柄数).下面我们使用zabbix监控nginx. nginx的安装 如果想要查看nginx的服务状态,在对nginx进行源码安装的时候要选中–with-http_stub_status_module模块. 1.解压安装包: [[email prot