美文网首页
zabbix 添加监控Nginx

zabbix 添加监控Nginx

作者: _弗求弗迪_ | 来源:发表于2017-09-12 17:19 被阅读0次
    1. 配置nginx 注意:ngx_status名称要与shell脚本对应的名称相同

      location ~ /ngx_status {
           stub_status on;
           access_log off;
           allow 127.0.0.1;
           allow 192.168.1.0/24;
           deny all;
       }
      
    2. 配置zabbix_agentd.conf

             UserParameter=nginx.status[*],/scripts/ngx_status.sh $1
      
    3. 配置shell脚本:注意脚本名与zabbix_agented.conf里的名字相同

           #!/bin/bash
           ##############################################################
           # File Name: ngx_status.sh
           # Version: V1.0
           # Author: Tim
           # Organization: opensource
           # Created Time : 2017-06-06 15:27:06
           # Description:
           ##############################################################
           
           
           HOST="192.168.0.199"
           PORT="80"
           
           function ping {
               /sbin/pidof nginx | wc -l
           }
           
           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}'
           }
           
           $1
      
    4. 导入nginx_zbx_export_templates.xml

       <?xml version="1.0" encoding="UTF-8"?>
       <zabbix_export>
           <version>3.2</version>
           <date>2017-06-08T01:12:31Z</date>
           <groups>
               <group>
                   <name>Templates</name>
               </group>
           </groups>
           <templates>
               <template>
                   <template>Template App Nginx Service</template>
                   <name>Template App Nginx Service</name>
                   <description/>
                   <groups>
                       <group>
                           <name>Templates</name>
                       </group>
                   </groups>
                   <applications>
                       <application>
                           <name>Nginx status</name>
                       </application>
                   </applications>
                   <items>
                       <item>
                           <name>Nginx_accepts</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[accepts]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_active</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[active]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_handled</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[handled]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_reading</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[reading]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_requests</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[requests]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_waiting</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[waiting]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                       <item>
                           <name>Nginx_writing</name>
                           <type>0</type>
                           <snmp_community/>
                           <multiplier>0</multiplier>
                           <snmp_oid/>
                           <key>nginx.status[writing]</key>
                           <delay>30</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/>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>Nginx status</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                       </item>
                   </items>
                   <discovery_rules/>
                   <httptests/>
                   <macros/>
                   <templates/>
                   <screens/>
               </template>
           </templates>
           <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>7EC25C</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[accepts]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>1</sortorder>
                           <drawtype>0</drawtype>
                           <color>274482</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[active]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>2</sortorder>
                           <drawtype>0</drawtype>
                           <color>2B5429</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[handled]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>3</sortorder>
                           <drawtype>0</drawtype>
                           <color>8048B4</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[reading]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>4</sortorder>
                           <drawtype>0</drawtype>
                           <color>FD5434</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[requests]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>5</sortorder>
                           <drawtype>0</drawtype>
                           <color>790E1F</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[waiting]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>6</sortorder>
                           <drawtype>0</drawtype>
                           <color>87AC4D</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App Nginx Service</host>
                               <key>nginx.status[writing]</key>
                           </item>
                       </graph_item>
                   </graph_items>
               </graph>
           </graphs>
       </zabbix_export>
      

    相关文章

      网友评论

          本文标题:zabbix 添加监控Nginx

          本文链接:https://www.haomeiwen.com/subject/hxgcsxtx.html