📊 Netdata
零設定即時系統監控,開箱即用
Netdata 安裝後立刻監控數千項系統指標,內建 Web 介面可即時瀏覽 CPU、記憶體、磁碟、網路等數據,無需複雜設定,適合快速建立伺服器監控。
安裝(一鍵安裝腳本)
$ wget -O /tmp/netdata-kickstart.sh https://get.netdata.cloud/kickstart.sh
sh /tmp/netdata-kickstart.sh --stable-channel --disable-telemetry安裝完成後,Netdata 即自動開始收集系統指標,無需任何設定。
$ sudo systemctl status netdata存取 Web 介面
預設 Netdata 只監聽本機 127.0.0.1:19999,可透過 SSH Tunnel 從本地存取:
$ # 在本機執行:建立 SSH 通道
ssh -L 19999:localhost:19999 user@你的伺服器IP
# 然後在本機瀏覽器開啟:
# http://localhost:19999設定與告警
主設定檔:/etc/netdata/netdata.conf
[global]
run as user = netdata
web files owner = root
# 資料保留時間
history = 86400 # 1 天(秒)
[web]
bind to = 127.0.0.1 # 只監聽本機(生產環境推薦)自訂告警(/etc/netdata/health.d/custom.conf)
# 磁碟使用率超過 90% 告警
alarm: disk_full
on: disk.space
lookup: max -1m for used_perc
units: %
every: 1m
warn: $this > 80
crit: $this > 90
info: 磁碟使用率過高
# 告警發送到 email
alarm: always_alert
to: sysadmin@example.com$ # 設定 email 告警
sudo vim /etc/netdata/health_alarm_notify.confEMAIL_SENDER="netdata@example.com"
DEFAULT_RECIPIENT_EMAIL="admin@example.com"
SEND_EMAIL="YES"透過 Nginx 反向代理存取
server {
listen 443 ssl;
server_name netdata.example.com;
# 基本認證(保護 Netdata 不被公開存取)
auth_basic "Netdata";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_pass http://127.0.0.1:19999;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}$ sudo apt install -y apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd admin常用操作
| 操作 | 指令 |
|---|---|
| 重啟 Netdata | sudo systemctl restart netdata |
| 查看收集的圖表 | curl -s http://localhost:19999/api/v1/charts | jq '.charts | keys[]' | head -20 |
| 測試告警設定 | sudo -u netdata /usr/libexec/netdata/plugins.d/alarm-notify.sh test |
| 查看日誌 | sudo tail -f /var/log/netdata/error.log |