侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Zabbix监控Nginx_client_status及Nginx_socket_status

2023-11-12 星期日 / 0 评论 / 0 点赞 / 64 阅读 / 24277 字

Zabbix_server 3.0.5 Zabbix_agentd 3.0.5 Zabbix_agentd端(被监控端) Nignx在编译安装时需添加模块支持:--with-http_stub_sta

Zabbix_server 3.0.5

Zabbix_agentd 3.0.5

Zabbix_agentd端(被监控端)

Nignx在编译安装时需添加模块支持:--with-http_stub_status_module 

Nginx的配置:

server{listen 80;server_name 127.0.0.1;location /nginxstatus {stub_status on;access_log off;allow 127.0.0.1;deny all;}}

#只允许本机获取nginxstatus信息

Zabbix_agentd配置:

vim /etc/zabbix/scritps/nginx_status.sh

#!/bin/bash# Set VariablesHOST="127.0.0.1"PORT="80"# Functions to return nginx statsfunction active {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Active' | awk '{print $NF}'}function reading {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Reading' | awk '{print $2}'}function writing {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Writing' | awk '{print $4}'}function waiting {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | grep 'Waiting' | awk '{print $6}'}function accepts {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $1}'}function handled {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $2}'}function requests {/usr/bin/curl "http://$HOST:$PORT/nginxstatus" 2>/dev/null | awk NR==3 | awk '{print $3}'}# Run the requested function$1

chmod +x nginx_status.sh

vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx_status.conf

UserParameter=nginx.accepts,/etc/zabbix/scripts/nginx_status.sh acceptsUserParameter=nginx.handled,/etc/zabbix/scripts/nginx_status.sh handledUserParameter=nginx.requests,/etc/zabbix/scripts/nginx_status.sh requestsUserParameter=nginx.connections.active,/etc/zabbix/scripts/nginx_status.sh activeUserParameter=nginx.connections.reading,/etc/zabbix/scripts/nginx_status.sh readingUserParameter=nginx.connections.writing,/etc/zabbix/scripts/nginx_status.sh writingUserParameter=nginx.connections.waiting,/etc/zabbix/scripts/nginx_status.sh waiting

重启Zabbix_agentd

/etc/init.d/zabbix-agent restart

Zabbix_server端(监控端):

Zabbix_server端获取监控数据:

/usr/local/zabbix/bin/zabbix_get -s Zabbix_agentd端IP -p 10050 -k nginx.accepts

44365129

添加Nginx监控模板Template App Nginx Service.xml

<?xml version="1.0" encoding="UTF-8"?><zabbix_export>    <version>3.0</version>    <date>2017-05-03T07:45:00Z</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</name>                </application>            </applications>            <items>                <item>                    <name>Nginx Accepts</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.accepts</key>                    <delay>30</delay>                    <history>365</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Connections Active</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.connections.active</key>                    <delay>30</delay>                    <history>365</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Connections Reading</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.connections.reading</key>                    <delay>30</delay>                    <history>365</history>                    <trends>365</trends>                    <status>0</status>                    <value_type>3</value_type>                    <allowed_hosts>localhost</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>0</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Connections Waiting</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.connections.waiting</key>                    <delay>30</delay>                    <history>365</history>                    <trends>365</trends>                    <status>0</status>                    <value_type>3</value_type>                    <allowed_hosts>localhost</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>0</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Connections Writing</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.connections.writing</key>                    <delay>30</delay>                    <history>365</history>                    <trends>365</trends>                    <status>0</status>                    <value_type>3</value_type>                    <allowed_hosts>localhost</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>0</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Handled</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.handled</key>                    <delay>30</delay>                    <history>365</history>                    <trends>365</trends>                    <status>0</status>                    <value_type>3</value_type>                    <allowed_hosts>localhost</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>0</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>                <item>                    <name>Nginx Requests</name>                    <type>0</type>                    <snmp_community/>                    <multiplier>0</multiplier>                    <snmp_oid/>                    <key>nginx.requests</key>                    <delay>30</delay>                    <history>365</history>                    <trends>365</trends>                    <status>0</status>                    <value_type>3</value_type>                    <allowed_hosts>localhost</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>0</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</name>                        </application>                    </applications>                    <valuemap/>                    <logtimefmt/>                </item>            </items>            <discovery_rules/>            <macros/>            <templates/>            <screens/>        </template>    </templates>    <graphs>        <graph>            <name>Nginx Clients 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>0000EE</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.connections.active</key>                    </item>                </graph_item>                <graph_item>                    <sortorder>1</sortorder>                    <drawtype>0</drawtype>                    <color>EE0000</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.connections.writing</key>                    </item>                </graph_item>                <graph_item>                    <sortorder>2</sortorder>                    <drawtype>0</drawtype>                    <color>EEEE00</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.connections.waiting</key>                    </item>                </graph_item>                <graph_item>                    <sortorder>3</sortorder>                    <drawtype>0</drawtype>                    <color>00EE00</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.connections.reading</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>00EE00</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.accepts</key>                    </item>                </graph_item>                <graph_item>                    <sortorder>0</sortorder>                    <drawtype>0</drawtype>                    <color>EE0000</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.handled</key>                    </item>                </graph_item>                <graph_item>                    <sortorder>1</sortorder>                    <drawtype>0</drawtype>                    <color>EEEE00</color>                    <yaxisside>0</yaxisside>                    <calc_fnc>2</calc_fnc>                    <type>0</type>                    <item>                        <host>Template App Nginx Service</host>                        <key>nginx.requests</key>                    </item>                </graph_item>            </graph_items>        </graph>    </graphs></zabbix_export>

关联对应的主机,根据需求设置修改相关的配置(Triggers Macros)

广告 广告

评论区