Grafana+Prometheus+php-fpm-exporter監控PHP-FPM狀態(五)

1. 啓用php-fpm狀態功能

php-fpmnginx一樣內建了一個狀態頁,對於想了解php-fpm的狀態以及監控php-fpm非常有幫助。爲了後續的Prometheus監控,我們需要先了解php-fpm狀態頁是怎麼回事。

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = debug

[www]
listen = /tmp/php-cgi.sock
listen.backlog = 1024
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 300
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10240
pm.status_path = /phpfpm_status
ping.path = /ping
request_terminate_timeout = 1200
pm.process_idle_timeout = 0
request_slowlog_timeout = 5
slowlog = var/log/slow.log
rlimit_files = 65535

默認情況下爲pm.status_path = /status,當然也可以改成其他的等等。

如上,配置後,重啓即開啓了php-fpm狀態功能

2. nginx配置

在默認主機裏面加上location或者你希望能訪問到的主機裏面。

server {
        listen 80;
        server_name 127.0.0.1;
        location /nginx_status {
                stub_status on;
                access_log off;
        }
        location ~ ^/(phpfpm_status|ping)$ {
				fastcgi_pass unix:/tmp/php-cgi.sock;
               # fastcgi_pass  127.0.0.1:9000;
	        	 allow 127.0.0.1;
		         deny all;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }

	error_log  /var/log/wwwlogs/127error.log ;
	access_log  /var/log/wwwlogs/127access.log main;

}

3. 重啓nginx/php-fpm

service php-fpm restart
service nginx restart

4.測試

[root@iz conf.d]# curl http://127.0.0.1/phpfpm_status
pool:                 www
process manager:      dynamic
start time:           21/Nov/2019:10:42:33 +0800
start since:          4498
accepted conn:        4896
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       19
active processes:     1
total processes:      20
max active processes: 14
max children reached: 0
slow requests:        153
[root@iz conf.d]# curl http://127.0.0.1/ping
pong
[root@iz conf.d]# 
[root@iz conf.d]# curl http://127.0.0.1/nginx_status
Active connections: 5 
server accepts handled requests
 3481898 3481898 3526133 
Reading: 0 Writing: 1 Waiting: 4 

5. php-fpm 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,緩慢請求的數量

6. 被監控服務器安裝PHP-FPM-exporter

	6.1 下載:`php-fpm-exporter`
地址:*https://github.com/bakins/php-fpm-exporter/releases*

	6.2 安裝php-fpm-exporter
 mkdir -p /usr/local/php-fpm-exporter
 mv php-fpm-exporter.linux.amd64 /usr/local/php-fpm-exporter/php-fpm-exporter
 chmod +x /usr/local/php-fpm-exporter/php-fpm-exporter
 	6.3 啓動php-fpm-exporter
nohup ./php-fpm-exporter --addr 172.19.14.250:9190 --endpoint http://127.0.0.1/phpfpm_status  > /usr/local/php-fpm-exporter/php-fpm-exporter.log 2>&1 &

7.Prometheus端

7.1 配置Prometheus
# vim /usr/local/prometheus/prometheus.yml
scrape_configs:
  - job_name: 'PHP-FPM'
    static_configs:
      - targets:
        - 172.19.14.250:9190
7.2 重啓
 systemctl restart prometheus

8.Grafana端

dashboards.id 推薦3901

模板地址:https://grafana.com/dashboards/3901

在這裏插入圖片描述

參考:http://www.ttlsa.com/php/use-php-fpm-status-page-detail/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章