不多说,首先你需要开启php-fpm的状态页,请参考凉白开前面写的文章《启用php-fpm状态详解》,然后更我一步一步来完成zabbix对php-fpm的监控。
zabbix客户端配置
增加自定义key
代码如下 | 复制代码 |
# cat zabbix_agentd.conf | grep 'php-fpm' UserParameter=php-fpm.status[*],/usr/bin/curl -s "http://127.0.0.1/status?xml" | grep "<$1>" | awk -F'>|<' '{ print $$3}' |
在此没有额外使用脚本,比网络上的其他脚本要精练不少!
重启zabbix客户端
代码如下 | 复制代码 |
# killall zabbix_agentd # /usr/local/zabbix-3.0.0/sbin/zabbix_agentd |
依据自己的情况来重启你的zabbix客户端
zabbix管理后台配置
导入php-fpm模板
附件中会给出模板(备注:更多关于zabbix模板内容,请看前面关于模板的章节,我不在多说)
进入后台->configuration->templates->import(右侧)->选择在ttlsa下载的模板->最后点击import。至此php-fpm模板已经导入到zabbix中。
Link/关联模板
接下来需要把php-fpm模板link到你的主机上,进入后台->configuration->点击你的主机->templates->输入php-fpm模板名称,点击add,最后点击update即可
zabbix监控php-fpm
还有另外一种更快的方法,点击php-fpm模板,然后将主机添加进去即可,都是一些简单的操作,不在截图演示!
效果展示
latest数据
慢日志数量
php-fm processes
php-fpm进程退出会触发告警,我不多做演示,有相关问题在此留言。继续关注zabbix,继续关注ttlsa。最近比较忙,都没来得及给投稿的小伙伴发红包,实在是抱歉了!
监控模块
代码如下 | 复制代码 |
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>3.0</version> <date>2015-11-09T14:19:16Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template App PHP-FPM</template> <name>Template App PHP-FPM</name> <description>php-fpm监控模板 - create by 凉白开()</description> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>php-fpm</name> </application> </applications> <items> <item> <name>php-fpm is running</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>proc.num[php-fpm,,,]</key> <delay>60</delay> <history>30</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>is live</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap> <name>Service state</name> </valuemap> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[max-listen-queue]</key> <delay>60</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>max-listen-queue</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[slow-requests]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <delta>2</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>slow-requests</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[total-processes]</key> <delay>60</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>total-processes</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[max-children-reached]</key> <delay>60</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>max-children-reached</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[start-since]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units>uptime</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>start-since</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[max-active-processes]</key> <delay>60</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>max-active-processes</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[active-processes]</key> <delay>60</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>active-processes</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[idle-processes]</key> <delay>60</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>idle-processes</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[listen-queue-len]</key> <delay>60</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>accepts</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[listen-queue]</key> <delay>60</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>listen-queue</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>php-fpm status $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>php-fpm.status[accepted-conn]</key> <delay>60</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>accepted-conn</description> <inventory_link>0</inventory_link> <applications> <application> <name>php-fpm</name> </application> </applications> <valuemap/> <logtimefmt/> </item> </items> <discovery_rules/> <macros/> <templates/> <screens/> </template> </templates> <triggers> <trigger> <expression>{Template App PHP-FPM:proc.num[php-fpm,,,].last()}=0</expression> <name>php-fpm was down!</name> <url/> <status>0</status> <priority>4</priority> <description>PHP-FPM进程数:0,请注意</description> <type>0</type> <dependencies/> </trigger> </triggers> <graphs> <graph> <name>php-fpm processes</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>00C800</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[active-processes]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>C80000</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[idle-processes]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>0000C8</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[max-active-processes]</key> </item> </graph_item> <graph_item> <sortorder>3</sortorder> <drawtype>0</drawtype> <color>C800C8</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[total-processes]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>php-fpm slow 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>00C800</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[slow-requests]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>php listen queue</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>00C800</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[listen-queue]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>C80000</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[listen-queue-len]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>0000C8</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template App PHP-FPM</host> <key>php-fpm.status[max-listen-queue]</key> </item> </graph_item> </graph_items> </graph> </graphs> </zabbix_export> |
时间: 2024-10-26 01:29:10