适用于服务器日常巡检和资源监控自动化,确保系统稳定运行。
监控CPU、内存和磁盘使用率,超过阈值时输出告警并记录日志。
1. 将脚本保存为 `system_monitor.sh`; 2. 赋予执行权限:`chmod +x system_monitor.sh`; 3. 手动运行一次:`./system_monitor.sh`; 4. 如需持续监控,取消脚本末尾 while 循环的注释,并将脚本加入 crontab 或使用 systemd 定时执行; 5. 日志记录在 `/var/log/system_monitor.log`; 6. 可自定义告警方式(如 email/slack),需修改脚本中的 `ALERT_METHOD` 及相关配置。
bc, top, free, df (均为系统自带)