首页 / NGINX / zabbix监控nginx
zabbix监控nginx
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了zabbix监控nginx,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含12732字,纯文字阅读大概需要19分钟。
内容图文
![zabbix监控nginx](/upload/InfoBanner/zyjiaocheng/972/8bcb83d43e224376a437899d8243cd23.jpg)
1、安装http_stub_status_module模块
./configure --prefix=/usr/local/openresty --with-http_stub_status_module
2、nginx.conf中添加
location /status { stub_status on; access_log off; allow 127.0.0.1;#allow可以写多个 }
3、在/etc/zabbix/zabbix_agentd.d目录下创建userparameter_znginx.conf
# # This is a sample zabbix_agentd config file. # Put it to /etc/zabbix/zabbix_agentd.conf.d or otherwise integrate into agent config. # Edit to your needs. # set HOST and PORT varable UserParameter=nginx.check[*],/etc/zabbix/libexec/znginx/znginx.sh $1
4、在/etc/zabbix/libexec/znginx目录下创建znginx.sh
#!/bin/bash HOST="localhost" PORT="80" ##function ping () { echo `/sbin/pidof nginx | wc -l` } active () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'` } reading () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'` } writing () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'` } waiting () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'` } accepts () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $1}'` } handled () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $2}'` } requests () { echo `/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $3}'` } error () { echo "$0: [ping|active|reading|writing|waiting|accepts|handled|requests] nginx_port" } ###main [ $# -lt 1 ]&&error&&exit 1 if [ $1 != "ping" ]&&[ $1 != "active" ]&&[ $1 != "reading" ]&&[ $1 != "writing" ]&&[ $1 != "waiting" ]&&[ $1 != "accepts" ]&&[ $1 != "handled" ]&&[ $1 != "requests" ];then error exit 1 fi ###function callable case $1 in ping) ping;; active) active;; reading) reading;; writing) writing;; waiting) waiting;; accepts) accepts;; handled) handled;; requests) requests;; *) error;; esac exit 0
5、导入模板,将以下内容保存到本地zbx_export_templates.xml文件中,在zabbix server中导入模板
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>3.4</version> <date>2018-11-30T09:30:02Z</date> <groups> <group> <name>Templates/nginx</name> </group> </groups> <templates> <template> <template>Template App Nginx Web Server znginx</template> <name>Template App Nginx Web Server znginx</name> <description/> <groups> <group> <name>Templates/nginx</name> </group> </groups> <applications> <application> <name>nginx monitor</name> </application> </applications> <items> <item> <name>Nginx accepted client connections</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[accepts]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>nginx 开启到现在,总共处理了N个连接</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx active connections</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[active]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>活跃的连接数量</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx handled connections</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[handled]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>Nginx开启到现在,成功创建N次握手</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx boot status</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[ping]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>返回值1代表启动,0为停止</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx reading the request header</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[reading]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>Nginx 开启到现在,读取客户端的连接数.</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx client requests</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[requests]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>nginx 开启到现在,总共处理了N个请求</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx idle client connections waiting for a request</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[waiting]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> <item> <name>Nginx writing the response back to the client</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>nginx.check[writing]</key> <delay>60s</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description>nginx开启到现在,响应数据到客户端的数量</description> <inventory_link>0</inventory_link> <applications> <application> <name>nginx monitor</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <master_item/> </item> </items> <discovery_rules/> <httptests/> <macros/> <templates/> <screens/> </template> </templates> <graphs> <graph> <name>Nginx connections 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 App Nginx Web Server znginx</host> <key>nginx.check[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 App Nginx Web Server znginx</host> <key>nginx.check[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 App Nginx Web Server znginx</host> <key>nginx.check[writing]</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 App Nginx Web Server znginx</host> <key>nginx.check[waiting]</key> </item> </graph_item> </graph_items> </graph> <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 App Nginx Web Server znginx</host> <key>nginx.check[ping]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>Nginx total connections</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 App Nginx Web Server znginx</host> <key>nginx.check[accepts]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>FFFF33</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App Nginx Web Server znginx</host> <key>nginx.check[handled]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>0000EE</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App Nginx Web Server znginx</host> <key>nginx.check[requests]</key> </item> </graph_item> </graph_items> </graph> </graphs> </zabbix_export>
6、主机配置中的模板中添加Template App Nginx Web Server znginx
内容总结
以上是互联网集市为您收集整理的zabbix监控nginx全部内容,希望文章能够帮你解决zabbix监控nginx所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。