在 Ubuntu 上監控 Node.js 應用程序的性能和資源使用情況有多種方法。以下是一些常用的工具和方法:
pm2pm2 是一個流行的 Node.js 進程管理器,它提供了監控、日志管理和自動重啟等功能。
pm2sudo npm install pm2 -g
pm2 start app.js --name my-app
pm2 monit
nodemonnodemon 是一個用于監視文件變化并自動重啟 Node.js 應用的工具。
nodemonsudo npm install nodemon -g
nodemon app.js
htophtop 是一個交互式的進程查看器,可以用來監控系統的 CPU、內存、網絡等資源使用情況。
htopsudo apt update
sudo apt install htop
htophtop
toptop 是一個基本的系統監視工具,可以顯示當前運行的進程及其資源使用情況。
toptop
vmstatvmstat 可以報告虛擬內存統計信息,以及 CPU 使用情況。
vmstatvmstat 1
iostatiostat 可以報告 CPU 和輸入/輸出統計信息。
iostatsudo apt update
sudo apt install sysstat
iostatiostat -x 1
netstat 或 ssnetstat 和 ss 可以用來查看網絡連接、路由表、接口統計等信息。
netstatnetstat -tuln
ssss -tuln
dstatdstat 是一個多功能的性能監視工具,可以顯示 CPU、內存、網絡和磁盤使用情況。
dstatsudo apt update
sudo apt install dstat
dstatdstat
glancesglances 是一個跨平臺的系統監視工具,可以監控 CPU、內存、磁盤、網絡等資源。
glancessudo pip install glances
glancesglances
Prometheus 和 GrafanaPrometheus 是一個開源的監控系統和時間序列數據庫,Grafana 是一個開源的分析和監控平臺。
Prometheus 和 Grafanasudo apt update
sudo apt install prometheus grafana
Prometheus 和 Grafana根據官方文檔配置 Prometheus 和 Grafana,以便監控你的 Node.js 應用。
通過這些工具和方法,你可以全面監控你的 Node.js 應用在 Ubuntu 上的性能和資源使用情況。