本文主要是針對與添加php-fpm方法,生產環境有個坑,填下,初始環境不是我做的,我是來填坑的,
!
以源碼安裝為例:
目錄環境:
/usr/local/php/etc/php-fpm.conf
/usr/local/nginx/conf/nginx.conf
------------------------------------------------------------
一、開始按照書上配的,發現沒有sock文件,當然訪問就報錯了
server { listen 127.0.0.1:80; server_name 127.0.0.1; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ ^/(phpfpm_status)$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } } # curl 127.0.0.1/phpfpm_status502報錯
查看了一下nginx的error日志:
*100011 connect() to unix:/tmp/php-fcgi.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /phpfpm_status HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fcgi.sock:", host: "127.0.0.1"二、查了查網上發現:
其中fastcgi_pass為配置nginx與php-fpm的交互路徑,一般有兩種方式
任選其中一種即可,但必須和php-fpm的配置一致。
三、解決方法:
重啟nginx # vim /usr/local/nginx/conf/nginx.conf server { listen 127.0.0.1:80; server_name 127.0.0.1; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ ^/(phpfpm_status)$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } } # /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload # curl 127.0.0.1/phpfpm_status pool: www process manager: dynamic start time: 20/Jun/2017:17:22:19 +0800 start since: 2245 accepted conn: 40 listen queue: 0 max listen queue: 0 listen queue len: 128 idle processes: 1 active processes: 1 total processes: 2 max active processes: 2 max children reached: 0 slow requests: 0 可以了 php-fpm status狀態值詳解 pool:fpm池子名稱,大多數為www process manager:進程管理方式,值:static,dynamic or ondemand 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,那說明你的大進程數量太小了,需要設置大點四、監控腳本:
(1)shell腳本,此腳本是抄襲的
#!/bin/bash source /etc/bashrc >/dev/null 2>&1 source /etc/profile >/dev/null 2>&1 LOG=/var/log/zabbix/phpfpmstatus.log curl -s http://localhost/phpfpmstatus >$LOG pool(){ 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: $1 {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(2)python腳本,這個是自己寫的,寫的不好,還望海涵。
#!/usr/bin/env python #__*__coding:utf8__*__ import urllib2,sys,os def Php_status(): php_status_dirt = {} request_status_list = [] php_status_list = ["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"] php_url = 'http://127.0.0.1/phpfpm_status' req = urllib2.Request(php_url) response = urllib2.urlopen(req) request_list = response.read().split() # request_status_list=[request_list[1],request_list[4],request_list[11],request_list[14],request_list[17],request_list[21],request_list[25],request_list[28],request_list[31],request_list[34],request_list[38],request_list[42],request_list[45]] #以下數字位置都是上面截出來的,為了美觀,將位置作為了列表,在用位置列表定位request_list中的值['www', 'dynamic', '57795', '5424', '0', '0', '128', '2', '1', '3', '3', '0', '0', 'www', 'dynamic', '57795', '5424', '0', '0', '128', '2', '1', '3', '3', '0', '0'],并追加到request_status_list里面 #position--->request_list--->(request_status_list+php_status_list)--->php_status_dirt position=[1,4,11,14,17,21,25,28,31,34,38,42,45] for i in position: request_status_list.append(request_list[i]) for i in range(len(php_status_list)): php_status_dirt[php_status_list[i]] = request_status_list[i] if len(sys.argv) is not 2 or str(sys.argv[1]) not in php_status_dirt.keys(): print "Usage: php_stauts.py $1 {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}" exit(1) else: print php_status_dirt[str(sys.argv[1])] if __name__ == '__main__': try: Php_status() except urllib2.URLError,e: print "%s,there may be something wrong with php!" %e五、配置監控擴展
被監控主機端,zabbix_agentd.conf文件中添加上這個:
UserParameter=phpfpm[*],/etc/zabbix/scripts/phpfpm_status.py $1或者
UserParameter=phpfpm[*],/etc/zabbix/scripts/phpfpm_status.sh $1六、將腳本放置在/etc/zabbix/scripts/目錄下
chmod +x phpfpm.py七、測試
[root@zabbix_server-12-155 ~]# zabbix_get -s 10.1.12.177 -k phpfpm[s] Usage: php_stauts.py $1 {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} [root@zabbix_server-12-155 ~]# zabbix_get -s 10.1.12.177 -k phpfpm[pool] www接下來就是添加監控項了,模版我是在這下的https://www.ttlsa.com/zabbix/zabbix-monitor-php-fpm-status/
參考并鳴謝:
技術貼:
http://www.cnblogs.com/metasequoia/p/5806582.html
http://www.linuxidc.com/Linux/2015-04/116301.htm
https://www.ttlsa.com/zabbix/zabbix-monitor-php-fpm-status/
書籍:《zabbix企業級分布式監控系統》
另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前名稱:zabbix添加php監控-創新互聯
當前網址:http://www.2m8n56k.cn/article6/dodjig.html
成都網站建設公司_創新互聯,為您提供建站公司、定制開發、企業網站制作、服務器托管、云服務器、網站改版
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯