zabbix自定义key监察和控制nginx和fpm(网址并发数)【

作者:电脑系统

nginx配置新增

location /php_fpm_status
        {
                allow 127.0.0.1;
                deny all;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
nginx需要reload

1、修改 zabbix_agentd.conf,添加zabbix_agent 配置目录,以下是我本机的zabbix的配置: 将以下行的注释去掉

六、zabbix网页配置

nginx.status[accepts] 整形(每秒差值)

监控fpm,主要讲解监控动态并发数

4、重启zabbix_agent和zabbix_server,使用zabbix_get测试,如下:

zabbix配置(vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/fpm.conf)

UserParameter=fpm.status[*],sh /usr/local/zabbix/check_fpm.sh  -o $1
重启zabbix agent。pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd 

背景:

一、 nginx编译参数

监控nginx,主要讲解监控并发数

--prefix=/usr/local/nginx --with-http_stub_status_module

zabbix编译参数的查看:

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

5、web端添加监控项: 在主机上添加监控项:
分分快三全天计划网站 1

四、写脚本获取nginx的状态

监控脚本(/usr/local/zabbix/check_nginx.sh):
#!/bin/sh
#nginx status
#Active connections: 1 
#server accepts handled requests

#Reading: 0 Writing: 1 Waiting: 0 
while getopts "o:" opt
do
        case $opt in
                o ) option=$OPTARG;;
                ? )
                echo 'parameter is wrong!'
                exit 1;;
        esac
done
if [ ! "${option}" ];then
        echo "parameter is null"        
        exit 1
fi

if [[ ${option} == "active" ]];then
        curl -s 127.0.0.1/status |grep '^Active connections' |awk '{print $NF}'
elif [[ ${option} == "accepts" ]];then
        curl -s 127.0.0.1/status |awk 'NR==3'|awk '{print $1}'
fi

分分快三全天计划网站 2

/usr/local/php/etc/php-fpm.conf fpm配置新增

pm.status_path = /php_fpm_status
fpm需要重启。

图形预览:

二、nginx配置新增

location /status {
                allow 127.0.0.1;
                deny all;
                stub_status on;
                access_log off;
        }
重启nginx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

脚本说明,脚本需要输入三个参数分别是:mysql用户、mysql用户密码、mysql状态各项指标如下: uptime:运行时长单位s、 threads:开启的会话数、 question(questions):服务器启动以来客户的问题(查询)数目 sq(Slow queries): 慢查询数量 open(opens):服务器已经打开的数据库表的数量 ftable(Flush tables):服务器已经执行的flush ...、refresh和reload命令的数量 opent(open tables):通过命令是用的数据库的表的数量,以服务器启动开始 qps(Queries per second avg):select语句平均查询时间

zabbix网页配置

fpm.status[conn]

 

zabbix本身提供了很多可选的监控项,可以满足绝大部分的监控需求。有时候由于业务需求,需要自定义监控项。 下面以创建mysql自定义监控项为例,分享如何创建zabbix自定义监控项。

三、测试下看看能不能获取nginx状态

curl 127.0.0.1/status

3、在/usr/local/etc/zabbix_agentd.conf.d/目录下添加监控项配置文件get_mysql_status.conf,内容如下:

五、zabbix配置(/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf)

UserParameter=nginx.status[*],sh /usr/local/zabbix/check_nginx.sh -o $1
重启zabbix agentd(pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd )

添加完成后可以看到新增监控项如下:

测试看看能不能获取到fpm的状态

curl 127.0.0.1/php_fpm_status
pool:                 www
process manager:      static
start time:           02/Jun/2017:17:45:05  0800
start since:          58677
accepted conn:        10753843
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       249
active processes:     1
total processes:      250
max active processes: 251
max children reached: 0
slow requests:        426

分分快三全天计划网站 3

写脚本获取fpm的状态

监控脚本(/usr/local/zabbix/check_fpm.sh):
#!/bin/sh
#20170603 fpm status
#curl 127.0.0.1/php_fpm_status
#pool:                 www
#process manager:      static
#start time:           02/Jun/2017:17:45:05  0800
#start since:          59022
#accepted conn:        10768453
#listen queue:         0
#max listen queue:     0
#listen queue len:     0
#idle processes:       249
#active processes:     1
#total processes:      250
#max active processes: 251
#max children reached: 0
#slow requests:        426
while getopts "o:" opt
do
        case $opt in
                o ) option=$OPTARG;;
                ? )
                echo 'parameter is wrong!'
                exit 1;;
        esac
done
if [ ! "${option}" ];then
        echo "parameter is null"        
        exit 1
fi

if [[ ${option} == "conn" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^accepted conn'|awk '{print $NF}'
elif [[ ${option} == "idle" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^idle processes'|awk '{print $NF}'
elif [[ ${option} == "active" ]];then
curl -s 127.0.0.1/php_fpm_status |grep '^active processes'|awk '{print $NF}'
fi

将此行注释去掉后,zabbix_agentd启动后会自动扫描/usr/local/etc/zabbix_agentd.conf.d/目录下所有的.conf文件,并加载。

分分快三全天计划网站 4

变成:

原文来自:

zabbix版本:3.0.3 操作系统:CentOS 7 mysql版本:5.7.1

#!/bin/sh

case $3 in
uptime)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $2}'
;;
threads)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $4}'
;;
question)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $6}'
;;
sq)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $9}'
;;
open)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $11}'
;;
ftable)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $14}'
;;
opent)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $17}'
;;
qps)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'  '{print $22}'
;;
*)

添加图形:

2、编写监控脚本/usr/local/zabbix/zabbix-script/get_mysql_status.sh,脚本如下(脚本存放目录可以自定义):

环境说明:

#Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf
#zabbix_get -s 127.0.0.1 -k get_mysql_status[root,weiming,open]
   679

实现步骤:

UserParameter=get_mysql_status[*],/usr/local/zabbix/zabbix-script/get_mysql_status.sh $1 $2 $3
Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划 系统运维 工作日志