Ubuntu下Apache性能监控实操指南
一 系统层快速排查
二 Apache自带模块 mod_status
<Location /server-status>
SetHandler server-status
Require ip 127.0.0.1 ::1 # 生产环境建议仅放通可信IP
</Location>
ExtendedStatus On
三 日志分析与命令行工具
四 长期监控与可视化方案
五 告警与自动化
#!/usr/bin/env bash
if ! systemctl is-active --quiet apache2; then
echo "$(date): Apache DOWN, restarting..." >> /var/log/apache_monitor.log
systemctl start apache2
fi
#!/usr/bin/env bash
LOG="/var/log/apache2/error.log"
ERR=$(grep -c "error" "$LOG" 2>/dev/null || echo 0)
if [ "$ERR" -gt 5 ]; then
echo "Apache Error Alert: $ERR errors" | mail -s "Apache Alert" you@example.com
fi