和之前写过的Zabbix 3.2 agentd监控Nginx性能原理差不多,都是通过web引擎输出status信息来进行性能监控,一般情况下我们需要对ReqPerSec、BytesPerSec、BusyWorkers、IdleWorkers四个数据进行关注。
开启Apache Status
Listen 80 <VirtualHost *:80> CustomLog /dev/null common ErrorLog /dev/null <Location "/server-status"> SetHandler server-status Require ip 127.0.0.1 </Location> </VirtualHost> |
我这里生产环境监控的是一台WHM服务器,默认开启apache status,访问地址为http://127.0.0.1:80/whm-server-status?auto,正常情况下应该如下页面内容:
Apache Server Status for 127.0.0.1 (via 127.0.0.1)
Server Version: Apache/2.4.37 (cPanel) OpenSSL/1.0.2p mod_bwlimited/1.4
Server MPM: prefork
Server Built: Oct 29 2018 18:29:24
Current Time: Thursday, 22-Nov-2018 13:48:50 CST
Restart Time: Thursday, 22-Nov-2018 13:48:35 CST
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 15 seconds
Server load: 0.05 0.09 0.08
Total accesses: 7 – Total Traffic: 54 kB – Total Duration: 19687
CPU Usage: u.02 s0 cu0 cs0 – .133% CPU load
.467 requests/sec – 3686 B/second – 7.7 kB/request – 2812.43 ms/request
7 requests currently being processed, 4 idle workers……………
创建Apache Status采集脚本
mkdir /usr/local/zabbix/share/scripts vim /usr/local/zabbix/share/scripts/apache_status.sh #!/bin/bash URL="http://127.0.0.1:80/whm-server-status?auto" function ReqPerSec(){ /usr/bin/curl -s $URL |grep ReqPerSec|awk '{print $2}' } function BytesPerSec(){ /usr/bin/curl -s $URL |grep BytesPerSec|awk '{print $2}' } function BusyWorkers(){ /usr/bin/curl -s $URL |grep BusyWorkers|awk '{print $2}' } function IdleWorkers(){ /usr/bin/curl -s $URL |grep IdleWorkers|awk '{print $2}' } function ping(){ /usr/sbin/pidof httpd|wc -l } $1 chmod +x /usr/local/zabbix/share/scripts/apache_status.sh chown zabbix:zabbix /usr/local/zabbix/share/scripts/apache_status.sh vim /usr/local/zabbix/etc/zabbix_agentd.conf #加入 UserParameter=apache.status[*],/usr/local/zabbix/share/scripts/apache_status.sh "$1" /etc/init.d/zabbix_agent restart #特别看下这个带单位的:单位我这里写的Bps,Bytes每秒的意思,但在zabbix中,它会自动帮你换算成KBps。 |
zabbix中导入模板并调用到主机即可
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>3.2</version> <date>2017-08-02T08:54:28Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template App Apache Status</template> <name>Template App Apache Status</name> <description/> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>Apache Status</name> </application> </applications> <items> <item> <name>Busy Workers</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>apache.status[BusyWorkers]</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>Apache Status</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>Bytes per second</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>apache.status[BytesPerSec]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>Bps</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>Apache Status</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>Idle Workers</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>apache.status[IdleWorkers]</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>Apache Status</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>apache alive</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>apache.status[ping]</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>3</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Apache Status</name> </application> </applications> <valuemap> <name>Service state</name> </valuemap> <logtimefmt/> </item> <item> <name>Requests per Second</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>apache.status[ReqPerSec]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</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>Apache Status</name> </application> </applications> <valuemap/> <logtimefmt/> </item> </items> <discovery_rules/> <httptests/> <macros/> <templates/> <screens/> </template> </templates> <graphs> <graph> <name>Apache Bandwidth</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 Apache Status</host> <key>apache.status[BytesPerSec]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>Apache Requests</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 Apache Status</host> <key>apache.status[ReqPerSec]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>Apache Workers</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>F63100</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App Apache Status</host> <key>apache.status[BusyWorkers]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>1A7C11</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App Apache Status</host> <key>apache.status[IdleWorkers]</key> </item> </graph_item> </graph_items> </graph> </graphs> <value_maps> <value_map> <name>Service state</name> <mappings> <mapping> <value>0</value> <newvalue>Down</newvalue> </mapping> <mapping> <value>1</value> <newvalue>Up</newvalue> </mapping> </mappings> </value_map> </value_maps> </zabbix_export> |
本文抄自:https://www.centos.bz/2017/08/zabbix-monitor-apache-status/。
暂时没有评论!