眼前多少难甘事,自古男儿当自强。这篇文章主要讲述zabbix-邮件报警及nginx自治愈相关的知识,希望能为你提供帮助。
1.nginx监控模板nginx_status.xml
< ?xml version="1.0" encoding="UTF-8"?>
< zabbix_export>
< version> 4.0< /version>
< date> 2019-01-18T09:07:55Z< /date>
< groups>
< group>
< name> Templates< /name>
< /group>
< /groups>
< templates>
< template>
< template> NGINX_Check_Statuc< /template>
< name> NGINX_Check_Statuc< /name>
< description/>
< groups>
< group>
< name> Templates< /name>
< /group>
< /groups>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< items>
< item>
< name> nginx_listen_80< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> net.tcp.listen[80]< /key>
< delay> 5s< /delay>
< history> 30d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> nginx_listen_443< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> net.tcp.listen[443]< /key>
< delay> 5s< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 总共处理的连接数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,accepts]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 对后端发起的活动连接数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,active]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 成功创建的握手数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,handled]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 读取到客户端的Header信息数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,reading]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 总共处理的请求数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,requests]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 等待下一次请求指令的驻留连接数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,waiting]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 返回给客户端的Header信息数< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[nginx_status,80,writing]< /key>
< delay> 5s< /delay>
< history> 365d< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< item>
< name> Nginx 状态码< /name>
< type> 7< /type>
< snmp_community/>
< snmp_oid/>
< key> nginx.status[status]< /key>
< delay> 5s< /delay>
< history> 365d< /history>
< trends> 365d< /trends>
< status> 1< /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/>
< inventory_link> 0< /inventory_link>
< applications>
< application>
< name> nginx< /name>
< /application>
< /applications>
< valuemap/>
< logtimefmt/>
< preprocessing/>
< jmx_endpoint/>
< timeout> 3s< /timeout>
< url/>
< query_fields/>
< posts/>
< status_codes> 200< /status_codes>
< follow_redirects> 1< /follow_redirects>
< post_type> 0< /post_type>
< http_proxy/>
< headers/>
< retrieve_mode> 0< /retrieve_mode>
< request_method> 0< /request_method>
< output_format> 0< /output_format>
< allow_traps> 0< /allow_traps>
< ssl_cert_file/>
< ssl_key_file/>
< ssl_key_password/>
< verify_peer> 0< /verify_peer>
< verify_host> 0< /verify_host>
< master_item/>
< /item>
< /items>
< discovery_rules/>
< httptests/>
< macros/>
< templates/>
< screens/>
< /template>
< /templates>
< triggers>
< trigger>
< expression> NGINX_Check_Statuc:nginx.status[status].last()< > 1< /expression>
< recovery_mode> 0< /recovery_mode>
< recovery_expression/>
< name> Nginx_status< /name>
< correlation_mode> 0< /correlation_mode>
< correlation_tag/>
< url/>
< status> 0< /status>
< priority> 4< /priority>
< description/>
< type> 0< /type>
< manual_close> 0< /manual_close>
< dependencies/>
< tags/>
< /trigger>
< trigger>
< expression> NGINX_Check_Statuc:net.tcp.listen[80].last()< > 1< /expression>
< recovery_mode> 0< /recovery_mode>
< recovery_expression/>
< name> HOST.NAME listen_80< /name>
< correlation_mode> 0< /correlation_mode>
< correlation_tag/>
< url/>
< status> 0< /status>
< priority> 4< /priority>
< description/>
< type> 0< /type>
< manual_close> 0< /manual_close>
< dependencies/>
< tags/>
< /trigger>
< trigger>
< expression> NGINX_Check_Statuc:net.tcp.listen[443].last()< > 1< /expression>
< recovery_mode> 0< /recovery_mode>
< recovery_expression/>
< name> HOST.NAME listen_443< /name>
< correlation_mode> 0< /correlation_mode>
< correlation_tag/>
< url/>
< status> 0< /status>
< priority> 4< /priority>
< description/>
< type> 0< /type>
< manual_close> 0< /manual_close>
< dependencies/>
< tags/>
< /trigger>
< /triggers>
< graphs>
< graph>
< name> Nginx_client_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> 003300< /color>
< yaxisside> 0< /yaxisside>
< calc_fnc> 2< /calc_fnc>
< type> 0< /type>
< item>
< host> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,active]< /key>
< /item>
< /graph_item>
< graph_item>
< sortorder> 1< /sortorder>
< drawtype> 0< /drawtype>
< color> 2774A4< /color>
< yaxisside> 0< /yaxisside>
< calc_fnc> 2< /calc_fnc>
< type> 0< /type>
< item>
< host> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,reading]< /key>
< /item>
< /graph_item>
< graph_item>
< sortorder> 2< /sortorder>
< drawtype> 0< /drawtype>
< color> EE0000< /color>
< yaxisside> 0< /yaxisside>
< calc_fnc> 2< /calc_fnc>
< type> 0< /type>
< item>
< host> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,waiting]< /key>
< /item>
< /graph_item>
< graph_item>
< sortorder> 3< /sortorder>
< drawtype> 0< /drawtype>
< color> AA00AA< /color>
< yaxisside> 0< /yaxisside>
< calc_fnc> 2< /calc_fnc>
< type> 0< /type>
< item>
< host> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,writing]< /key>
< /item>
< /graph_item>
< /graph_items>
< /graph>
< graph>
< name> Nginx_socket_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> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,accepts]< /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> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,handled]< /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> NGINX_Check_Statuc< /host>
< key> nginx.status[nginx_status,80,requests]< /key>
< /item>
< /graph_item>
< /graph_items>
< /graph>
< /graphs>
< /zabbix_export>
2.nginx编译安装参考??https://blog.51cto.com/taowenwu/4864239??
3.zabbix-agent自动安装脚本??https://blog.51cto.com/taowenwu/5213052??
4.配置文件修改
root@ubuntu:/apps/zabbix_agent/conf.d# cat nginx.conf
UserParameter=nginx.status[*],/bin/bash /apps/zabbix_agent/conf.d/nginx_status.sh $1 $2 $3
5.监控脚本nginx_status.sh
#!/bin/bash
nginx_status_fun() #函数内容
NGINX_PORT=$1#端口,函数的第一个参数是脚本的第二个参数,即脚本的第二个参数是段端口号
NGINX_COMMAND=$2#命令,函数的第二个参数是脚本的第三个参数,即脚本的第三个参数是命令
nginx_active()#获取nginx_active数量,以下相同,这是开启了nginx状态但是只能从本机看到
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| grep Active | awk print $NF
nginx_reading() #获取nginx_reading状态的数量
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| grep Reading | awk print $2
nginx_writing()
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| grep Writing | awk print $4
nginx_waiting()
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| grep Waiting | awk print $6
nginx_accepts()
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| awk NR==3 | awk print $1
nginx_handled()
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| awk NR==3 | awk print $2
nginx_requests()
/usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2> /dev/null| awk NR==3 | awk print $3
case $NGINX_COMMAND in
active)
nginx_active;
; ;
reading)
nginx_reading;
; ;
writing)
nginx_writing;
; ;
waiting)
nginx_waiting;
; ;
accepts)
nginx_accepts;
; ;
handled)
nginx_handled;
; ;
requests)
nginx_requests;
esac
main() #主函数内容
case $1 in #分支结构,用于判断用户的输入而进行响应的操作
nginx_status) #当输入nginx_status就调用nginx_status_fun,并传递第二和第三个参数
nginx_status_fun $2 $3;
; ;
*) #其他的输入打印帮助信息
echo $"Usage: $0 nginx_status key"
esac #分支结束符
main $1 $2 $3
chmod +xnginx_status.sh
#测试
root@ubuntu:/apps/zabbix_agent/conf.d# ./nginx_status.sh nginx_status 80 active
1
6.测试
root@ubuntu:~# zabbix_get -s 192.168.47.53 -p 10050 -k "nginx.status[nginx_status,80,active]"
1
7.2.用户添加报警媒介
推荐阅读
- Samaba文件共享服务
- 这个 Spring Boot 项目真的强,强大的代码生成器让前端和后台代码一键生成!
- Windows安全认证是如何进行的([NTLM篇])
- 如何利用Python随机从list中挑选一个元素
- Centos 把yum源软件包迁移到内网安装的方法
- matlab/simulink可变阻尼座椅悬架振动自适应控制设计与分析
- markdown设置字体为红色
- centos安装chromium
- 数据类型