当前位置:   article > 正文

zabbix监控mysql内存_Zabbix监控Nginx,php-fpm和MySQL占用内存数和进程个数

zabbix mysql进程负载(cpu、内存)和存活监控

Zabbix通过自定义脚本监控Nginx,php-fpm和MySQL占用内存数和进程的个数。

首先,在zabbix脚本目录下添加一个脚本,写入如下代码

#!/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 "$1" 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: $0 {php_fpm|php_fpm_num|nginx|nginx_num|mysqld|mysqld_num}"

esac

保存之后修改其属组和属主为zabbix.zabbix,然后新建一个文件process.log,同样设置属主和属组为zabbix.zabbix

然后编辑zabbix_agentd.conf文件,在最后添加上下面这段代码,并重启zabbix_agentd服务

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

之后就可以在web页面添加item,生成图表了,注意top取到的内存单位是KB,所以在定义item的时候需要自定义单位和设定倍数

eee5a10dd5815fc67592b08da2b04aee.png

生成的各个程序占用内存大小的图形如下

18a8389392d498dab1482c4c00e4ccfc.png

生成的各个程序的进程个数图形如下,可以设定触发器,当进程满足触发其条件时发送报警

3e8cdefef6bc792f9df9a26c1d0e1f8f.png

一些Zabbix相关教程集合:

ZABBIX 的详细介绍:请点这里

ZABBIX 的下载地址:请点这里

0b1331709591d260c1c78e86d0c51c18.png

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号