設置監控 nginx/php-fpm 性能及狀態

在nginx/php-fpm 常常會需要監控性能的參數,有時在性能不足時才知道往哪調整是有立杆見影的效果,在 nginx/php-fpm 都要在其配置檔上進行開啟記錄性能參數,設置如下:

nginx.conf

server
{
  listen 80;
  server_name localhost;  # 這邊也可以使用 localhost 即僅限本機查詢
    location ~ /nginx.status {
         stub_status on;
         access_log off;
         allow 127.0.0.1;
         deny all;
         }

  location ~ /status            # 設置的 php-fpm 性能查詢
  {
    allow 127.0.0.1;
    fastcgi_pass 127.0.0.1:9000;
    include /etc/nginx/fastcgi_params;
    fastcgi_param PATH_INFO "/";
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  }
}

然後在你的 php-fpm (我的環境是 /usr/local/etc/php-fpm.d/www.conf )相關的配置中找到一行 pm.status_path=/status 將他前面用 ; 註解的拿掉後重啟 php-fpm 及 nginx

然後就可以透過指令 curl 或 metricbeat 或自行撰寫的腳本來收集及處理性能的參數

nginx

20181207-nginx-status

php-fpm

20181207-php-fpm-status

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.