zabbix 自定义脚本监控 php

1.开启php 状态页面
/etc/php-fpm.d/www.conf
pm.status_path = /status

2、修改nginx的配置文件,通过Nginx访问PHP-FPM状态
    location ~ ^/(status|ping)$ {

    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}

3.访问测试phpfpm_status  根据个人配置的情况使用ip或者域名测试
[root@linux-node4 conf.d]# curl http://127.0.0.1/status
pool:                 www
process manager:      dynamic
start time:           16/Jun/2018:21:57:13 -0400
start since:          434
accepted conn:        41
listen queue:         0
max listen queue:     0
listen queue len:     128
idle processes:       5
active processes:     1
total processes:      6
max active processes: 1
max children reached: 0
slow requests:        0
pool #fpm池名称,大多数为www
process manager #进程管理方式dynamic或者static
start time #启动日志,如果reload了fpm,时间会更新
start since #运行时间
accepted conn #当前池接受的请求数
listen queue #请求等待队列,如果这个值不为0,那么需要增加FPM的进程数量
max listen queue #请求等待队列最高的数量
listen queue len #socket等待队列长度
idle processes #空闲进程数量
active processes #活跃进程数量
total processes #总进程数量
max active processes #最大的活跃进程数量(FPM启动开始计算)
max children reached #进程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量过小,可以适当调整。

4.创建脚本
mkdir /etc/zabbix/scripts
vim php-fpm_status.sh   chmod +x php-fpm_status.sh
#########################################################################
# File Name: php-fpm_status.sh
#########################################################################
#!/bin/bash

listenqueue(){       #处于等待状态中的连接数,如果不为0,需要增加php-fpm进程数
    wget --quiet -O - http://wangwei520.top/status?auto |grep "listen queue:"|grep -vE "len|max"|awk 
'{print$3}'
}

listenqueuelen(){  #处于等待连接队列的套接字大小
    wget --quiet -O - http://wangwei520.top/status?auto |grep "listen queue len" |awk '{print$4}'
}

idle(){          #处于空闲状态的进程数
    wget --quiet -O - http://wangwei520.top/status?auto |grep "idle processes" |awk '{print$3}'
}
active(){       #处于活动状态的进程数
    wget --quiet -O - http://wangwei520.top/status?auto |grep "active" |awk '{print$3}'|grep -v 
"process"
}
total(){        #进程总数
    wget --quiet -O - http://wangwei520.top/status?auto |grep "total processes" |awk '{print$3}'
}

mactive(){    #从php-fpm启动到现在的进程处于活动状态数

    wget --quiet -O - http://wangwei520.top/status?auto |grep "max active processes:" |awk '{print$4}'
}

$1

5、zabbix配置键值
cat check_service.conf chmod +x check_service.conf
UserParameter=php[*],/etc/zabbix/scripts/php-fpm_status.sh $1
systemctl  restart zabbix-agent

6、server端测试
zabbix_get -s 192.168.0.1 -p 10050 -k "php[total processes]"  #有数据说明正确

服务端配置:
导入模板
wget  wangwei520.top/zbx_templates_php-fpm.xml #下载
选择模板导入   

请输入图片描述
创建客户端的主机
请输入图片描述

请输入图片描述

请输入图片描述

请输入图片描述

请输入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值