• zabbix监控php-fpm的性能


    zabbix通过自定义item监控php-fpm性能情况做触发器,做图形,发邮件

    首先php-fpm的性能数据是要通过页面获取,所以需要在php-fpm的配置文件中添加一下语句

    一般在/usr/local/php/etc/php-fpm.conf

    pm.status_path = /status

    重启php-fpm

    在nginx的配置文件中加入页面匹配

    /usr/local/nginx/conf/nginx.conf

    location ~ ^/(status|ping)$
        {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

    }

    重启nginx

    curl http://127.0.0.1/status获取性能页面

    pool – fpm池子名称,大多数为www
    process manager – 进程管理方式,值:static, dynamic or ondemand. dynamic
    start time – 启动日期,如果reload了php-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,那说明你的最大进程数量太小了,请改大一点。
    slow requests – 启用了php-fpm slow-log,缓慢请求的数量

    php-fpm状态页比较个性化的一个地方是它可以带参数,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。用了以上参数可以获得知道格式的页面

    curl http://127.0.0.1/status?json

    curl http://127.0.0.1/status?xml

    curl http://127.0.0.1/status?html

    curl http://127.0.0.1/status?full

    参数full详解

    pid – 进程PID,可以单独kill这个进程. You can use this PID to kill a long running process.
    state – 当前进程的状态 (Idle, Running, …)
    start time – 进程启动的日期
    start since – 当前进程运行时长
    requests – 当前进程处理了多少个请求
    request duration – 请求时长(微妙)
    request method – 请求方法 (GET, POST, …)
    request URI – 请求URI
    content length – 请求内容长度 (仅用于 POST)
    user – 用户 (PHP_AUTH_USER) (or ‘-’ 如果没设置)
    script – PHP脚本 (or ‘-’ if not set)
    last request cpu – 最后一个请求CPU使用率。
    last request memorythe - 上一个请求使用的内存

    接着通过自定义item,加脚本,模板就可以通过zabbix监控性能

    添加监控的shlle脚本
    php-fpm_status.sh
    添加zabbix-agent配置
    php-fpm_status.conf
    重启zabbix-agent
    service zabbix-agent restart
    测试
    zabbix_get -s 127.0.0.1 -k slow.requests
    如果没有问题导入模板
    php-fpm_status.xml

    脚本

    listenqueue(){

            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'
    }
     
    listenqueuelen(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue len" |awk '{print$4}'
    }
     
    idle(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "idle processes" |awk '{print$3}'
    }
    active(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "active" |awk '{print$3}'|grep -v "process"
    }
    total(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "total processes" |awk '{print$3}'
    }
     
    mactive(){
     
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max active processes:" |awk '{print$4}'
    }
     
    since(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "start since: " |awk '{print$3}'
    }
     
    conn(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "accepted conn" |awk '{print$3}'
    }
     
    reached(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max children reached" |awk '{print$4}'
    }
    requests(){
            wget --quiet -O - http://127.0.0.1:80/status?auto |grep "slow requests" |awk '{print$3}'
    }
    $1
     
     
    模板
    vim php-fpm_status.conf
    UserParameter=idle.processe,/scripts/php-fpm_status.sh idle
    UserParameter=total.processes,/scripts/php-fpm_status.sh total
    UserParameter=active.processes,/scripts/php-fpm_status.sh active
    UserParameter=max.active.processes,/scripts/php-fpm_status.sh mactive
    UserParameter=listen.queue.len,/scripts/php-fpm_status.sh listenqueuelen
    UserParameter=listen.queue,/scripts/php-fpm_status.sh listenqueue
    UserParameter=start.since,/scripts/php-fpm_status.sh since
    UserParameter=accepted.conn,/scripts/php-fpm_status.sh conn
    UserParameter=max.children.reached,/scripts/php-fpm_status.sh reached
     
    接着就可以根据item创建图形,根据值创建触发器,根据触发器发送邮件或进一步做脚本操作
    UserParameter=slow.requests,/scripts/php-fpm_status.sh requests
  • 相关阅读:
    [React Testing] Create a Custom Render Function to Simplify Tests of Redux Components
    [React Testing] Test a Custom React Hook with React’s Act Utility and a Test Component
    Android之Android apk动态加载机制的研究
    Android之设备唯一识别
    ios之调用打电话,发短信,打开网址
    ios之如何读取plist
    android之卸载反馈的功能
    Android之针对webview的缓存
    Android之仿String的对象驻留
    Mac与Mac之中的共享方式
  • 原文地址:https://www.cnblogs.com/allmdzz/p/11278210.html
Copyright © 2020-2023  润新知