温馨提示×

如何监控Debian的Laravel

小樊
37
2026-08-28 00:29:08
栏目: 智能运维

在 Debian 上监控 Laravel 项目,通常分为 系统级监控Laravel 应用级监控日志/性能监控 三个层面。下面给你一套常用且实用的做法。


一、系统级监控(Debian 服务器)

1. 基础资源监控

top
htop        # 更友好
free -h     # 内存
df -h       # 磁盘

2. CPU / 内存 / 负载历史

vmstat 1
iostat -x 1
sar -u 1 5

3. 安装监控工具(推荐)

htop

sudo apt install htop

glances(Web + CLI)

sudo apt install glances
glances

二、Laravel 应用级监控

1. Laravel 自带日志

storage/logs/laravel.log

查看实时日志:

tail -f storage/logs/laravel.log

2. 使用 Laravel Horizon(队列监控 ✅)

如果用了 Redis 队列:

composer require laravel/horizon
php artisan horizon

访问:

https://your-domain.com/horizon

监控:

  • 队列失败
  • 队列延迟
  • Job 执行时间

3. Laravel Octane(高性能时必看)

如果你用:

  • Swoole
  • RoadRunner
php artisan octane:status

监控进程:

ps aux | grep octane

三、性能与请求监控(非常重要)

1. Laravel Debugbar(开发环境)

composer require barryvdh/laravel-debugbar --dev

可监控:

  • 请求耗时
  • SQL 查询
  • 内存占用

⚠️ 不要在生产环境启用


2. Laravel Telescope(开发/准生产)

composer require laravel/telescope
php artisan telescope:install
php artisan migrate

功能:

  • 请求监控
  • 异常
  • 队列
  • 邮件
  • 日志

四、生产环境专业监控方案

✅ 推荐组合(生产必选)

类型 工具
APM Sentry / Datadog / New Relic
日志 Laravel Log / rsyslog / journald
系统 Prometheus + Grafana
队列 Horizon
健康检查 自定义 / Supervisor

1. Sentry(强烈推荐)

composer require sentry/sentry-laravel

支持:

  • 异常自动上报
  • 性能监控
  • 错误趋势

2. Supervisor(进程监控)

确保 Laravel 队列 / Octane 不挂:

sudo apt install supervisor

示例:

[program:laravel-worker]
command=php /var/www/laravel/artisan queue:work
autostart=true
autorestart=true

五、HTTP / 接口监控

1. 健康检查接口

Route::get('/health', fn () => response()->json(['ok' => true]));

配合:

  • Uptime Kuma
  • Zabbix
  • Prometheus blackbox

六、数据库监控

sudo apt install mytop
mytop -u root -p

Laravel 中:

  • 慢查询日志
  • DB::enableQueryLog()(调试)

七、推荐监控架构(生产)

Debian
 ├─ Laravel
 │   ├─ Horizon(队列)
 │   ├─ Sentry(异常/性能)
 │   └─ Log(storage/logs)
 ├─ Prometheus + Grafana
 ├─ Supervisor
 └─ Uptime Kuma(HTTP 监控)

八、快速实战建议

如果你是:

  • 开发环境:Debugbar + Telescope
  • 线上小项目:Sentry + Horizon + 日志
  • 中大型生产:Prometheus + Grafana + Sentry

如果你愿意,我可以: ✅ 给你一份 Debian + Laravel 监控搭建完整命令清单
✅ 帮你设计 生产级监控架构图
✅ 针对 队列 / API / 高并发 场景定制方案

你现在 Laravel 是 开发还是生产?用 队列 / Redis / 高并发吗

0