在Debian系统中监控Node.js应用程序的运行状态可以通过多种工具和方法实现。以下是一些常用的监控方法:
npm install pm2 -g
。pm2 start app.js --name "my-app"
启动你的Node.js应用程序,并为其命名。pm2 list
pm2 logs my-app
pm2 monit
pm2 top
。sudo nano /etc/systemd/system/my-app.service
创建并编辑服务文件,根据你的应用程序进行调整。sudo systemctl start my-app
启动服务,并使用 sudo systemctl enable my-app
启用服务。sudo systemctl status my-app
查看服务状态。。const http = require('http');
http.createServer((req, res) => {
if (req.url === '/health') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('OK');
} else {
// Your app's normal routes go here
}
}).listen(3000);
curl http://localhost:3000/health
检查应用程序的健康状态。。通过上述方法,可以有效地监控Node.js应用在Debian上的运行状态、性能指标和日志,确保系统的稳定性和性能。