參考 http://xianglinhu.blog.51cto.com/5787032/1657570 覺的太實用了mysql
我這主要須要監控的程序以下:nginx
nginx redis mysql tomcat mongodb
redis
1 在客戶端編寫監控腳本內容以下sql
vi /usr/local/zabbix/scripts/processtatus.sh nginx(){ ps aux|grep "nginx"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } nginxcpu(){ ps aux|grep "nginx"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } redis(){ ps aux|grep "redis"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } rediscpu(){ ps aux|grep "redis"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } mysql(){ ps aux|grep "mysql"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } mysqlcpu(){ ps aux|grep "mysql"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } tomcat(){ ps aux|grep "tomcat"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } tomcatcpu(){ ps aux|grep "tomcat"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } mongodb(){ ps aux|grep "mongod"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } mongodbcpu(){ ps aux|grep "mongod"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } case "$1" in nginx) nginx ;; nginxcpu) nginxcpu ;; redis) redis ;; rediscpu) rediscpu ;; mysql) mysql ;; mysqlcpu) mysqlcpu ;; tomcat) tomcat ;; tomcatcpu) tomcatcpu ;; mongodb) mongodb ;; mongodbcpu) mongodbcpu ;; *) echo "Usage: $0 {nginx|nginxcpu|redis|rediscpu|mysql|mysqlcpu|tomcat|tomcatcpu|sentinel|sentinelcpu|mongodb|mongodbcpu}" ;; esac
而後修改腳本的權限,使用:
mongodb
chmod +x processstatus.shtomcat
2 在zabbix_agentd.con配置文件中末尾增長以下代碼:tcp
vi /usr/local/zabbix/etc/zabbix_agentd.conf 其中/usr/local/zabbix/scripts 這個目錄是自定義的能夠隨便設置 #monitor process UserParameter=process.nginx.memory,/usr/local/zabbix/scripts/processstatus.sh nginx UserParameter=process.nginx.cpu,/usr/local/zabbix/scripts/processstatus.sh nginxcpu UserParameter=process.redis.memory,/usr/local/zabbix/scripts/processstatus.sh redis UserParameter=process.redis.cpu,/usr/local/zabbix/scripts/processstatus.sh rediscpu UserParameter=process.mysql.memory,/usr/local/zabbix/scripts/processstatus.sh mysql UserParameter=process.mysql.cpu,/usr/local/zabbix/scripts/processstatus.sh mysqlcpu UserParameter=process.tomcat.memory,/usr/local/zabbix/scripts/processstatus.sh tomcat UserParameter=process.tomcat.cpu,/usr/local/zabbix/scripts/processstatus.sh tomcatcpu UserParameter=process.mongodb.memory,/usr/local/zabbix/scripts/processstatus.sh mongodb UserParameter=process.mongodb.cpu,/usr/local/zabbix/scripts/processstatus.sh mongodbcpu
最後重啓zabbix_agentd 服務 /etc/init.d/zabbix_agentd restartide
3 在服務端測試測試
[root@131 ~]# zabbix_get -s 192.168.127.130 -p 10050 -k process.nginx.memoryui
92812
表示正常
4 倒入模板,確認出圖
若是想更改監控的進程,能夠在模板裏面--items裏面更改
模板見附件!