Because of the need to monitor company-specific services, writing scripts to get the information that each process consumes system resources, using Zabbix to capture that data for the underlying monitoring of a particular process.
My main need to monitor the program is as follows:
Nginx Redis MySQL Tomcat Sentinel MongoDB openfire Kafka zookeeper Twemproxy Mycat
First, write the monitoring script on the agent side, the script content is as follows:
[[Email protected] ~]$ cat zabbix-2.4.4/scripts/processstatus.sh #!/bin/bash#license: Gpl#mail:[email protected] #date: 2015.06.02nginx () {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} '}sentinel () { ps aux|grep "Sentinel" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$6}; end{print sum} '}sentinelcpu () { ps aux|grep " Sentinel "|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} '}openfire () { ps aux|grep "OpenFire" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$6}; end{print sum} '}openfirecpu () { ps aux|grep "OpenFire" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$3}; end{print sum} '}kafka () { ps aux|grep "Kafka" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$6}; end{print sum} '} KAFKACPU () { ps aux|grep "Kafka" |grep -v "grep" |grep -v " processstatus.sh "|awk ' {sum+=$3}; end{print sum} '}zookeeper () { ps aux|grep "Zookeeper" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$6}; end{print sum} '} ZOOKEEPERCPU () { ps aux|grep "zookeeper" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$3}; end{print sum} '}twemproxy () { ps aux|grep "Twemproxy" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+= $6}; end{print sum} '}twemproxycpu () { ps aux|grep "Twemproxy" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$3}; end{print sum} '}mycat () { ps aux|grep "Mycat" |grep -v "grep" |grep -v " processstatus.sh "|awk ' {sum+=$6}; end{print sum} '}mycatcpu () { ps aux|grep "Mycat" |grep -v "grep" |grep -v "processstatus.sh" |awk ' {sum+=$3}; End{print sum} '}CASE  " " innginx" nginx;; NGINXCPU) nginxcpu;; Redis) Redis;; REDISCPU) rediscpu;; MySQL) MySQL; MYSQLCPU) mysqlcpu;; Tomcat) Tomcat;; TOMCATCPU) tomcatcpu;; Sentinel) Sentinel;; SENTINELCPU) sentinelcpu;; MongoDB) MongoDB;; MONGODBCPU) Mongodbcpu;;o Penfire) Openfire;;o PENFIRECPU) openfirecpu;; Kafka) Kafka;; KAFKACPU) kafkacpu;; Zookeeper) zookeeper;; ZOOKEEPERCPU) zookeepercpu;; Twemproxy) Twemproxy;; TWEMPROXYCPU) twemproxycpu;; Mycat) Mycat;; MYCATCPU) mycatcpu;; *) echo "usage: $0 {nginx|nginxcpu|redis|rediscpu|mysql|mysqlcpu|tomcat|tomcatcpu|sentinel| sentinelcpu|mongodb|mongodbcpu|openfire|openfirecpu|kafka|kafkacpu|zookeeper|zookeepercpu|twemproxy| TWEMPROXYCPU|MYCAT|MYCATCPU} "Esac
Then modify the permissions of the script, using:
chmod +x processstatus.sh
Add the following code at the end of the Zabbix_agentd.con configuration file:
[[email protected] ~]$ tail -23 zabbix-2.4.4/etc/zabbix_agentd.conf#monitor processuserparameter=process.nginx.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginxuserparameter=process.nginx.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginxcpuuserparameter=process.redis.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh redisuserparameter=process.redis.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh rediscpuuserparameter=process.mysql.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysqluserparameter=process.mysql.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysqlcpuuserparameter=process.tomcat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcatuserparameter=process.tomcat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcatcpuuserparameter=process.sentinel.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh Sentineluserparameter=process.sentinel.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh sentinelcpuuserparameter= Process.mongodb.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodbuserparameter= Process.mongodb.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodbcpuuserparameter= Process.openfire.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfireuserparameter= Process.openfire.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfirecpuuserparameter= Process.kafka.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafkauserparameter= Process.kafka.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafkacpuuserparameter= Process.zookeeper.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeeperuserparameter= Process.zookeeper.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeepercpuuserparameter= Process.twemproxy.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxyuserparameter=process.twemproxy.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxycpuuserparameter=process.mycat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh Mycatuserparameter=process.mycat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mycatcpu
Finally restart the ZABBIX_AGENTD service
Pkill Zabbixzabbix-2.4.4/sbin/zabbix_agentd
Then on the Zabbix server to use Zabbix_get to see if the corresponding data can be retrieved, as follows is the successful acquisition of data.
[Email protected] zabbix-2.4.4]# bin/zabbix_get-s 172.16.1.20-p 10050-k process.nginx.memory184876
Finally, you need to define the template in Zabbix. The template attachment link is below.
Zabbix Template Download
If the template cannot be downloaded, you can download the template in the attachment
It should be noted that the memory is worth the value of the unit is KB, so when the definition of the item by using a custom multiplier multiplied by 1000, the unit to byte, and the CPU occupancy rate is a number with a decimal point, so when the definition of the item needs to define the type is floating-point type, And this value is the CPU occupancy of the logical single core, so you need to define a custom multiplier, I experiment with the server is 2 CPUs, each CPU is 8 core 16 threads, so the custom multiplier is the original base divided by 32, the unit changed to% is good.
Here's what to do after you do it:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/DC/wKiom1Vtax6CV1W3AAQbYpR9NRQ039.jpg "title=" 1.jpg " alt= "Wkiom1vtax6cv1w3aaqbypr9nrq039.jpg"/>
This article is from the "Lemon" blog, be sure to keep this source http://xianglinhu.blog.51cto.com/5787032/1657570
Zabbix CPU and memory consumption of the monitoring process