zabbix經過自定義腳本監控nginx,php-fpm和mysql佔用內存數和進程的個數php
首先,在zabbix腳本目錄下添加一個腳本,寫入以下代碼mysql
#!/bin/bashnginx
#license:GPLweb
#mail:admin@huxianglin.cnsql
#date:2015.04.16bash
top -bn1>/usr/local/zabbix-2.4.4/scripts/process.logide
LOG=/usr/local/zabbix-2.4.4/scripts/process.logphp-fpm
php_fpm(){spa
grep "php-fpm" $LOG |awk '{sum+=$6}; END{print sum}'orm
}
php_fpm_num(){
grep "php-fpm" $LOG |wc -l
}
nginx(){
grep "nginx" $LOG |awk '{sum+=$6}; END{print sum}'
}
nginx_num(){
grep "nginx" $LOG |wc -l
}
mysqld(){
grep "mysqld" $LOG |awk '{sum+=$6}; END{print sum}'
}
mysqld_num(){
grep "mysqld" $LOG |wc -l
}
case "$1" in
php_fpm)
php_fpm
;;
php_fpm_num)
php_fpm_num
;;
nginx)
nginx
;;
nginx_num)
nginx_num
;;
mysqld)
mysqld
;;
mysqld_num)
mysqld_num
;;
*)
echo "Usage: $0 {php_fpm|php_fpm_num|nginx|nginx_num|mysqld|mysqld_num}"
esac
保存以後修改其屬組和屬主爲zabbix.zabbix,而後新建一個文件process.log,一樣設置屬主和屬組爲zabbix.zabbix
而後編輯zabbix_agentd.conf文件,在最後添加上下面這段代碼,並重啓zabbix_agentd服務
UserParameter=process.php_fpm,/usr/local/zabbix-2.4.4/scripts/processstatus.sh php_fpm
UserParameter=process.php_fpm_num,/usr/local/zabbix-2.4.4/scripts/processstatus.sh php_fpm_num
UserParameter=process.nginx,/usr/local/zabbix-2.4.4/scripts/processstatus.sh nginx
UserParameter=process.nginx_num,/usr/local/zabbix-2.4.4/scripts/processstatus.sh nginx_num
UserParameter=process.mysqld,/usr/local/zabbix-2.4.4/scripts/processstatus.sh mysqld
UserParameter=process.mysqld_num,/usr/local/zabbix-2.4.4/scripts/processstatus.sh mysqld_num
以後就能夠在web頁面添加item,生成圖表了,注意top取到的內存單位是KB,因此在定義item的時候須要自定義單位和設定倍數
生成的各個程序佔用內存大小的圖形以下
生成的各個程序的進程個數圖形以下,能夠設定觸發器,當進程知足觸發其條件時發送報警
本文出自 「檸檬」 博客,請務必保留此出處http://xianglinhu.blog.51cto.com/5787032/1633333