作为精通 Laravel 和 Linux 的 IT 工程师,我为您提供一套全面的性能监控方案,帮助您优化 Laravel 应用在 Linux 环境下的性能表现。
bash
htop
bash
vmstat 1
bash
iostat -x 1
bash
ss -tulnp
# 安装
sudo apt-get install sysstat
# 查看历史数据
sar -u # CPU
sar -r # 内存
sar -b # I/O
composer require laravel/telescope
php artisan telescope:install
php artisan migrate
访问 /telescope
查看详细请求、查询、队列等信息
composer require laravel/horizon
php artisan horizon:install
访问 /horizon
监控队列性能
composer require barryvdh/laravel-debugbar --dev
提供详细的请求时间、内存使用、SQL查询等信息
# 安装 Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v*/prometheus-*.*-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
# 配置 prometheus.yml 添加 Laravel 导出器
使用 prometheus-client-php
包导出 Laravel 指标:
comrequire promphp/prometheus_client_php
# 安装 New Relic PHP 代理
sudo apt-get install newrelic-php5
newrelic-install install
# 配置 Laravel 集成
# 安装 Blackfire 探针
wget -O - https://packages.blackfire.io/gpg.key | sudo apt-key add -
echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list
sudo apt-get update
sudo apt-get install blackfire-php
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
; php-fpm.conf
pm.status_path = /status
location ~ ^/(status|ping)$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
allow 127.0.0.1;
deny all;
}
tail -f storage/logs/laravel.log
goaccess /var/log/nginx/access.log --log-format=COMBINED
用于大规模日志收集和分析
OPcache 配置检查:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
队列工作进程检查:
supervisorctl status
数据库查询优化:
缓存检查:
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
通过以上综合监控方案,您可以全面掌握 Laravel 应用在 Linux 服务器上的性能表现,及时发现并解决性能瓶颈问题。