Zabbix Monitor nginx,php-fpm and MySQL memory usage and number of processes with custom scripts

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.