我这主要需要监控的程序如下:

nginx redis mysql tomcat  mongodb 

1 在客户端编写监控脚本内容如下

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

然后修改脚本的权限,使用:

chmod +x processstatus.sh

2  在zabbix_agentd.con配置文件中末尾增加如下代码:

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 restart

3 在服务端测试

[root@131 ~]# zabbix_get -s 192.168.127.130 -p 10050 -k process.nginx.memory

92812

表示正常

4 倒入模板,确认出图

wKiom1dFS5CC3i_0AAHuiExopO0042.png

wKioL1dFTLywAyurAAF924tBGfM431.png

如果想更改监控的进程,可以在模板里面–items里面更改

模板见附件!

发表评论

邮箱地址不会被公开。 必填项已用*标注