温馨提示×

debian js日志怎么监控

小樊
35
2026-10-07 02:59:54
栏目: 编程语言

在 Debian 上监控 JS(Node.js / 前端构建 / 浏览器)日志,常见做法取决于日志类型和运行环境。下面按场景给你一套实用方案。


一、Node.js 服务日志监控(最常见)

1. 基础:实时查看日志

tail -f /path/to/app.log

或 PM2 日志:

pm2 logs

2. 用 systemd 管理 Node 服务(推荐)

如果你用 systemd 启动 Node:

journalctl -u yourapp.service -f

日志位置:

/var/log/syslog
journalctl

3. 日志文件监控(自动告警)

inotifywait(简单)

apt install inotify-tools
inotifywait -m /var/log/js/app.log

logwatch / swatch

apt install swatch
swatch --watch /var/log/js/app.log --tail

二、Node.js 应用内日志方案(强烈推荐)

1. 使用 Winston / Pino

npm install winston

示例:

const winston = require('winston');
winston.add(new winston.transports.File({ filename: 'app.log' }));

2. PM2 + 日志管理

pm2 install pm2-logrotate

三、集中式日志监控(生产环境)

1. ELK(Elasticsearch + Logstash + Kibana)

  • Filebeat 采集 Debian 日志
  • 发送到 Elasticsearch
  • Kibana 可视化

2. Loki + Grafana(轻量)

apt install promtail loki

适合容器和 JS 服务

3. 云服务

  • Datadog
  • Sentry(错误日志极好)
  • Alibaba SLS / Tencent CLS

四、前端 JS 错误监控(浏览器)

如果是前端 JS:

  • Sentry
  • 自建错误上报接口
  • window.onerror

五、实战推荐组合(Debian 生产)

✅ Node + PM2
✅ Winston 写日志
✅ journalctl / pm2 logs
✅ Loki + Grafana 或 Sentry


如果你能告诉我:

  • 是 Node 后端 还是 前端 JS
  • 是否 生产环境
  • 是否用 Docker / PM2

我可以给你更精确的监控方案或配置文件。

0 踩