DevOps zabbix监控php状态

anewrer · November 10, 2019 · 5 hits

        通过 nginx 调用 php-fpm 来查询 php 的状态信息

        首先,在 php 的配置文件中添加一行

1
vim /usr/local/php/etc/php-fpm.conf
1
pm.status_path = /phpfpmstatus

        保存后重启 php-fpm

        在 nginx 配置文件中添加代码

123456789101112131415161718
server {     listen localhost:80;    server_name localhost;location /nginxstatus {   stub_status on;     access_log off;     allow 127.0.0.1;    allow 10.6.0.187;       deny all;   }location ~ ^/(phpfpmstatus)$ {        include fastcgi_params;        fastcgi_pass unix:/tmp/php-fcgi.sock;        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; }}

        保存后重启 nginx

        然后使用curl -s http://localhost/phpfpmstatus查看是否能够获取到 php 状态信息

        然后,在 zabbix 的脚本目录里面编辑执行脚本

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
#lincense:GPL#mail:admin@huxianglin.cn#date:2015.04.15
source /etc/bashrc >/dev/null 2>&1
source /etc/profile >/dev/null 2>&1LOG=/usr/local/zabbix-2.4.4/scripts/phpfpmstatus.logcurl -s http://localhost/phpfpmstatus >$LOG

(){  awk '/pool/ {print $NF}' $LOG
}
process_manager(){ awk '/process manager/ {print $NF}' $LOG
}
start_since(){  awk '/start since:/ {print $NF}' $LOG
}
accepted_conn(){        awk '/accepted conn:/ {print $NF}' $LOG
}
listen_queue(){        awk '/^(listen queue:)/ {print $NF}' $LOG
}
max_listen_queue(){        awk '/max listen queue:/ {print $NF}' $LOG
}
listen_queue_len(){        awk '/listen queue len:/ {print $NF}' $LOG
}
idle_processes(){        awk '/idle processes:/ {print $NF}' $LOG
}
active_processes(){        awk '/^(active processes:)/ {print $NF}' $LOG
}
total_processes(){        awk '/total processes:/ {print $NF}' $LOG
}
max_active_processes(){        awk '/max active processes:/ {print $NF}' $LOG
}
max_children_reached(){        awk '/max children reached:/ {print $NF}' $LOG
}
case "$1" in
pool)    pool    ;;process_manager)  process_manager ;;start_since)  start_since ;;accepted_conn)    accepted_conn   ;;listen_queue) listen_queue    ;;max_listen_queue) max_listen_queue    ;;listen_queue_len) listen_queue_len    ;;idle_processes)   idle_processes  ;;active_processes) active_processes    ;;total_processes)  total_processes ;;max_active_processes) max_active_processes    ;;max_children_reached) max_children_reached    ;;*)
echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}"
esac

        保存后退出,修改权限为

1
-rwxr-xr-x 1 zabbix zabbix 1770 4月  15 14:50 phpstatus.sh

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

12345678910111213
#to monitor php-fpmstatusUserParameter=phpfpm.status.pool,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh poolUserParameter=phpfpm.status.process.manager,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh process_managerUserParameter=phpfpm.status.start.since,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh start_sinceUserParameter=phpfpm.status.accepted.conn,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh accepted_connUserParameter=phpfpm.status.listen.queue,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh listen_queueUserParameter=phpfpm.status.max.listen.queue,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh max_listen_queueUserParameter=phpfpm.status.listen.queue.len,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh listen_queue_lenUserParameter=phpfpm.status.idle.processes,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh idle_processesUserParameter=phpfpm.status.active.processes,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh active_processesUserParameter=phpfpm.status.total.processes,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh total_processesUserParameter=phpfpm.status.max.active.processes,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh max_active_processesUserParameter=phpfpm.status.max.children.reached,/usr/local/zabbix-2.4.4/scripts/phpstatus.sh max_children_reached

        然后就可以在 web 端配置 item 监控 php 状态了

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.