Zabbix Monitor nginx,php-fpm and MySQL memory usage and number of processes with custom scripts
First, add a script under the Zabbix script directory and write the following code
#!/bin/bash
#license: GPL
#mail: admin@huxianglin.cn
#date: 2015.04.16
Top-bn1>/usr/local/zabbix-2.4.4/scripts/process.log
Log=/usr/local/zabbix-2.4.4/scripts/process.log
PHP_FPM () {
grep "PHP-FPM" $LOG |awk ' {sum+=$6}; End{print sum} '
}
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 "$" 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: $ {Php_fpm|php_fpm_num|nginx|nginx_num|mysqld|mysqld_num}"
Esac
After saving, modify its genus and owner to Zabbix.zabbix, then create a new file Process.log, also set the owner and the group as Zabbix.zabbix
Then edit the zabbix_agentd.conf file, add the following code at the end, and restart the ZABBIX_AGENTD service
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
You can then add item to the Web page, generate the chart, and note that the memory unit top is in KB, so you need to customize the unit and set multiple when you define the item
The graphs generated by each program occupy memory size are as follows
The number of processes generated by each program is graphically shown below, and triggers can be set to send alarms when a process satisfies its condition