Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2825118
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: LINUX

2014-01-03 14:22:19

###该内容主要是为留个备忘,感谢我的同事Bob在前面给我排雷!!
1:
在需要监控的网站的相应配置文件里()加入以下部分:

location /nginx-status {
       stub_status     on;
        access_log      off; 
        allow 127.0.0.1;
        allow xxx.xxx.xxx.xxx;#本机IP
        allow xxx.xxx.xxx.xxx;   #监控服务器的Ip
        deny all;
        }
2:
userparameter_nginx.conf 放到/usr/local/zabbix/etc/zabbix_agent.conf.d目录下,该文件的内容如下;

  1. UserParameter=nginx.accepts,/usr/local/zabbix/sbin/nginx-status.sh accepts
  2. UserParameter=nginx.handled,/usr/local/zabbix/sbin/nginx-status.sh handled
  3. UserParameter=nginx.requests,/usr/local/zabbix/sbin/nginx-status.sh requests
  4. UserParameter=nginx.connections.active,/usr/local/zabbix/sbin/nginx-status.sh active
  5. UserParameter=nginx.connections.reading,/usr/local/zabbix/sbin/nginx-status.sh reading
  6. UserParameter=nginx.connections.writing,/usr/local/zabbix/sbin/nginx-status.sh writing
  7. UserParameter=nginx.connections.waiting,/usr/local/zabbix/sbin/nginx-status.sh waiting
并在/usr/local/zabbix/etc/zabbix_agentd.conf中 include该文件;
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_nginx.conf

3:显然这里需要用到nginx_status.sh文件,该文件的位置在/usr/local/zabbix/sbin/下,该文件内容如下:

  1. #!/bin/bash# Script to fetch nginx statuses for tribily monitoring systems
  2. # Author: [email]krish@toonheart.com[/email]
  3. # License: GPLv2
  4.  
  5. HOST=lo***b.g***z.com ##要监控的域名
  6. HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'` ##和机器上的相对应
  7. PORT="8080"
  8. #webstatus=nginx-status

  9. # Functions to return nginx stats

  10. function active {
  11.         /usr/bin/curl "" 2>/dev/null| grep 'Active' | awk '{print $NF}'
  12.         }

  13. function reading {
  14.         /usr/bin/curl "" 2>/dev/null| grep 'Reading' | awk '{print $2}'
  15.         }

  16. function writing {
  17.         /usr/bin/curl "" 2>/dev/null| grep 'Writing' | awk '{print $4}'
  18.         }

  19. function waiting {
  20.         /usr/in/curl "" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
  21.         }

  22. function accepts {
  23.         /usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $1}'
  24.         }

  25. function handled {
  26.         /usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $2}'
  27.         }

  28. function requests {
  29.         /usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $3}'
  30.         }

  31. # Run the requested function
  32. $1
4:测试:
/usr/local/zabbix/bin/zabbix_get -s 客户端IP -p 10050 -k "nginx.connections.active"
7
5:在监控服务器上添加主机,并导入nginx模板,nginx模板!

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <zabbix_export version="1.0" date="14.03.11" time="08.48">
  3.   <hosts>
  4.     <host name="Nginx Status">
  5.       <proxy_hostid>0</proxy_hostid>
  6.       <useip>1</useip>
  7.       <dns></dns>
  8.       <ip>127.0.0.1</ip>
  9.       <port>10050</port>
  10.       <status>3</status>
  11.       <useipmi>0</useipmi>
  12.       <ipmi_ip>127.0.0.1</ipmi_ip>
  13.       <ipmi_port>623</ipmi_port>
  14.       <ipmi_authtype>0</ipmi_authtype>
  15.       <ipmi_privilege>2</ipmi_privilege>
  16.       <ipmi_username></ipmi_username>
  17.       <ipmi_password></ipmi_password>
  18.       <groups>
  19.         <group>cy2009</group>
  20.       </groups>
  21.       <triggers/>
  22.       <items>
  23.         <item type="7" key="nginx.accepts" value_type="3">
  24.           <description>Nginx Accepts</description>
  25.           <ipmi_sensor></ipmi_sensor>
  26.           <delay>30</delay>
  27.           <history>365</history>
  28.           <trends>365</trends>
  29.           <status>0</status>
  30.           <data_type>0</data_type>
  31.           <units></units>
  32.           <multiplier>0</multiplier>
  33.           <delta>0</delta>
  34.           <formula>0</formula>
  35.           <lastlogsize>0</lastlogsize>
  36.           <logtimefmt></logtimefmt>
  37.           <delay_flex></delay_flex>
  38.           <authtype>0</authtype>
  39.           <username></username>
  40.           <password></password>
  41.           <publickey></publickey>
  42.           <privatekey></privatekey>
  43.           <params></params>
  44.           <trapper_hosts>localhost</trapper_hosts>
  45.           <snmp_community></snmp_community>
  46.           <snmp_oid></snmp_oid>
  47.           <snmp_port>161</snmp_port>
  48.           <snmpv3_securityname></snmpv3_securityname>
  49.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  50.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  51.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  52.           <applications>
  53.             <application>Nginx</application>
  54.           </applications>
  55.         </item>
  56.         <item type="7" key="nginx.connections.active" value_type="3">
  57.           <description>Nginx Connections Active</description>
  58.           <ipmi_sensor></ipmi_sensor>
  59.           <delay>30</delay>
  60.           <history>365</history>
  61.           <trends>365</trends>
  62.           <status>0</status>
  63.           <data_type>0</data_type>
  64.           <units></units>
  65.           <multiplier>0</multiplier>
  66.           <delta>0</delta>
  67.           <formula>0</formula>
  68.           <lastlogsize>0</lastlogsize>
  69.           <logtimefmt></logtimefmt>
  70.           <delay_flex></delay_flex>
  71.           <authtype>0</authtype>
  72.           <username></username>
  73.           <password></password>
  74.           <publickey></publickey>
  75.           <privatekey></privatekey>
  76.           <params></params>
  77.           <trapper_hosts>localhost</trapper_hosts>
  78.           <snmp_community></snmp_community>
  79.           <snmp_oid></snmp_oid>
  80.           <snmp_port>161</snmp_port>
  81.           <snmpv3_securityname></snmpv3_securityname>
  82.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  83.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  84.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  85.           <applications>
  86.             <application>Nginx</application>
  87.           </applications>
  88.         </item>
  89.         <item type="7" key="nginx.connections.reading" value_type="3">
  90.           <description>Nginx Connections Reading</description>
  91.           <ipmi_sensor></ipmi_sensor>
  92.           <delay>30</delay>
  93.           <history>365</history>
  94.           <trends>365</trends>
  95.           <status>0</status>
  96.           <data_type>0</data_type>
  97.           <units></units>
  98.           <multiplier>0</multiplier>
  99.           <delta>0</delta>
  100.           <formula>0</formula>
  101.           <lastlogsize>0</lastlogsize>
  102.           <logtimefmt></logtimefmt>
  103.           <delay_flex></delay_flex>
  104.           <authtype>0</authtype>
  105.           <username></username>
  106.           <password></password>
  107.           <publickey></publickey>
  108.           <privatekey></privatekey>
  109.           <params></params>
  110.           <trapper_hosts>localhost</trapper_hosts>
  111.           <snmp_community></snmp_community>
  112.           <snmp_oid></snmp_oid>
  113.           <snmp_port>161</snmp_port>
  114.           <snmpv3_securityname></snmpv3_securityname>
  115.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  116.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  117.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  118.           <applications>
  119.             <application>Nginx</application>
  120.           </applications>
  121.         </item>
  122.         <item type="7" key="nginx.connections.waiting" value_type="3">
  123.           <description>Nginx Connections Waiting</description>
  124.           <ipmi_sensor></ipmi_sensor>
  125.           <delay>30</delay>
  126.           <history>365</history>
  127.           <trends>365</trends>
  128.           <status>0</status>
  129.           <data_type>0</data_type>
  130.           <units></units>
  131.           <multiplier>0</multiplier>
  132.           <delta>0</delta>
  133.           <formula>0</formula>
  134.           <lastlogsize>0</lastlogsize>
  135.           <logtimefmt></logtimefmt>
  136.           <delay_flex></delay_flex>
  137.           <authtype>0</authtype>
  138.           <username></username>
  139.           <password></password>
  140.           <publickey></publickey>
  141.           <privatekey></privatekey>
  142.           <params></params>
  143.           <trapper_hosts>localhost</trapper_hosts>
  144.           <snmp_community></snmp_community>
  145.           <snmp_oid></snmp_oid>
  146.           <snmp_port>161</snmp_port>
  147.           <snmpv3_securityname></snmpv3_securityname>
  148.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  149.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  150.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  151.           <applications>
  152.             <application>Nginx</application>
  153.           </applications>
  154.         </item>
  155.         <item type="7" key="nginx.connections.writing" value_type="3">
  156.           <description>Nginx Connections Writing</description>
  157.           <ipmi_sensor></ipmi_sensor>
  158.           <delay>30</delay>
  159.           <history>365</history>
  160.           <trends>365</trends>
  161.           <status>0</status>
  162.           <data_type>0</data_type>
  163.           <units></units>
  164.           <multiplier>0</multiplier>
  165.           <delta>0</delta>
  166.           <formula>0</formula>
  167.           <lastlogsize>0</lastlogsize>
  168.           <logtimefmt></logtimefmt>
  169.           <delay_flex></delay_flex>
  170.           <authtype>0</authtype>
  171.           <username></username>
  172.           <password></password>
  173.           <publickey></publickey>
  174.           <privatekey></privatekey>
  175.           <params></params>
  176.           <trapper_hosts>localhost</trapper_hosts>
  177.           <snmp_community></snmp_community>
  178.           <snmp_oid></snmp_oid>
  179.           <snmp_port>161</snmp_port>
  180.           <snmpv3_securityname></snmpv3_securityname>
  181.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  182.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  183.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  184.           <applications>
  185.             <application>Nginx</application>
  186.           </applications>
  187.         </item>
  188.         <item type="7" key="nginx.handled" value_type="3">
  189.           <description>Nginx Handled</description>
  190.           <ipmi_sensor></ipmi_sensor>
  191.           <delay>30</delay>
  192.           <history>365</history>
  193.           <trends>365</trends>
  194.           <status>0</status>
  195.           <data_type>0</data_type>
  196.           <units></units>
  197.           <multiplier>0</multiplier>
  198.           <delta>0</delta>
  199.           <formula>0</formula>
  200.           <lastlogsize>0</lastlogsize>
  201.           <logtimefmt></logtimefmt>
  202.           <delay_flex></delay_flex>
  203.           <authtype>0</authtype>
  204.           <username></username>
  205.           <password></password>
  206.           <publickey></publickey>
  207.           <privatekey></privatekey>
  208.           <params></params>
  209.           <trapper_hosts>localhost</trapper_hosts>
  210.           <snmp_community></snmp_community>
  211.           <snmp_oid></snmp_oid>
  212.           <snmp_port>161</snmp_port>
  213.           <snmpv3_securityname></snmpv3_securityname>
  214.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  215.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  216.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  217.           <applications>
  218.             <application>Nginx</application>
  219.           </applications>
  220.         </item>
  221.         <item type="7" key="nginx.requests" value_type="3">
  222.           <description>Nginx Requests</description>
  223.           <ipmi_sensor></ipmi_sensor>
  224.           <delay>30</delay>
  225.           <history>365</history>
  226.           <trends>365</trends>
  227.           <status>0</status>
  228.           <data_type>0</data_type>
  229.           <units></units>
  230.           <multiplier>0</multiplier>
  231.           <delta>0</delta>
  232.           <formula>0</formula>
  233.           <lastlogsize>0</lastlogsize>
  234.           <logtimefmt></logtimefmt>
  235.           <delay_flex></delay_flex>
  236.           <authtype>0</authtype>
  237.           <username></username>
  238.           <password></password>
  239.           <publickey></publickey>
  240.           <privatekey></privatekey>
  241.           <params></params>
  242.           <trapper_hosts>localhost</trapper_hosts>
  243.           <snmp_community></snmp_community>
  244.           <snmp_oid></snmp_oid>
  245.           <snmp_port>161</snmp_port>
  246.           <snmpv3_securityname></snmpv3_securityname>
  247.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  248.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  249.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  250.           <applications>
  251.             <application>Nginx</application>
  252.           </applications>
  253.         </item>
  254.       </items>
  255.       <templates/>
  256.       <graphs>
  257.         <graph name="Nginx Socket Status" width="900" height="200">
  258.           <ymin_type>0</ymin_type>
  259.           <ymax_type>0</ymax_type>
  260.           <ymin_item_key></ymin_item_key>
  261.           <ymax_item_key></ymax_item_key>
  262.           <show_work_period>1</show_work_period>
  263.           <show_triggers>1</show_triggers>
  264.           <graphtype>0</graphtype>
  265.           <yaxismin>0.0000</yaxismin>
  266.           <yaxismax>100.0000</yaxismax>
  267.           <show_legend>0</show_legend>
  268.           <show_3d>0</show_3d>
  269.           <percent_left>0.0000</percent_left>
  270.           <percent_right>0.0000</percent_right>
  271.           <graph_elements>
  272.             <graph_element item="Nginx Status:nginx.accepts">
  273.               <drawtype>0</drawtype>
  274.               <sortorder>0</sortorder>
  275.               <color>00EE00</color>
  276.               <yaxisside>0</yaxisside>
  277.               <calc_fnc>2</calc_fnc>
  278.               <type>0</type>
  279.               <periods_cnt>5</periods_cnt>
  280.             </graph_element>
  281.             <graph_element item="Nginx Status:nginx.handled">
  282.               <drawtype>0</drawtype>
  283.               <sortorder>0</sortorder>
  284.               <color>EE0000</color>
  285.               <yaxisside>0</yaxisside>
  286.               <calc_fnc>2</calc_fnc>
  287.               <type>0</type>
  288.               <periods_cnt>5</periods_cnt>
  289.             </graph_element>
  290.             <graph_element item="Nginx Status:nginx.requests">
  291.               <drawtype>0</drawtype>
  292.               <sortorder>1</sortorder>
  293.               <color>EEEE00</color>
  294.               <yaxisside>0</yaxisside>
  295.               <calc_fnc>2</calc_fnc>
  296.               <type>0</type>
  297.               <periods_cnt>5</periods_cnt>
  298.             </graph_element>
  299.           </graph_elements>
  300.         </graph>
  301.         <graph name="Nginx Clients Status" width="900" height="200">
  302.           <ymin_type>0</ymin_type>
  303.           <ymax_type>0</ymax_type>
  304.           <ymin_item_key></ymin_item_key>
  305.           <ymax_item_key></ymax_item_key>
  306.           <show_work_period>1</show_work_period>
  307.           <show_triggers>1</show_triggers>
  308.           <graphtype>0</graphtype>
  309.           <yaxismin>0.0000</yaxismin>
  310.           <yaxismax>100.0000</yaxismax>
  311.           <show_legend>0</show_legend>
  312.           <show_3d>0</show_3d>
  313.           <percent_left>0.0000</percent_left>
  314.           <percent_right>0.0000</percent_right>
  315.           <graph_elements>
  316.             <graph_element item="Nginx Status:nginx.connections.active">
  317.               <drawtype>0</drawtype>
  318.               <sortorder>0</sortorder>
  319.               <color>0000EE</color>
  320.               <yaxisside>0</yaxisside>
  321.               <calc_fnc>2</calc_fnc>
  322.               <type>0</type>
  323.               <periods_cnt>5</periods_cnt>
  324.             </graph_element>
  325.             <graph_element item="Nginx Status:nginx.connections.writing">
  326.               <drawtype>0</drawtype>
  327.               <sortorder>1</sortorder>
  328.               <color>EE0000</color>
  329.               <yaxisside>0</yaxisside>
  330.               <calc_fnc>2</calc_fnc>
  331.               <type>0</type>
  332.               <periods_cnt>5</periods_cnt>
  333.             </graph_element>
  334.             <graph_element item="Nginx Status:nginx.connections.waiting">
  335.               <drawtype>0</drawtype>
  336.               <sortorder>2</sortorder>
  337.               <color>EEEE00</color>
  338.               <yaxisside>0</yaxisside>
  339.               <calc_fnc>2</calc_fnc>
  340.               <type>0</type>
  341.               <periods_cnt>5</periods_cnt>
  342.             </graph_element>
  343.             <graph_element item="Nginx Status:nginx.connections.reading">
  344.               <drawtype>0</drawtype>
  345.               <sortorder>3</sortorder>
  346.               <color>00EE00</color>
  347.               <yaxisside>0</yaxisside>
  348.               <calc_fnc>2</calc_fnc>
  349.               <type>0</type>
  350.               <periods_cnt>5</periods_cnt>
  351.             </graph_element>
  352.           </graph_elements>
  353.         </graph>
  354.       </graphs>
  355.       <macros/>
  356.     </host>
  357.   </hosts>
  358.   <dependencies/>
  359. </zabbix_export>
然后即可显示相关内容,如果没有数据,查看日志文件,根据日志文件解决问题即可!


阅读(2453) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~