refactor: consolidate metric collection into single SSH calls and add support for SSH key authentication
This commit is contained in:
Regular → Executable
+15
@@ -2,15 +2,24 @@
|
||||
|
||||
# Monitor and restart metrics collector if it's not running
|
||||
# This script checks if collect_metrics.php is running and restarts it if needed
|
||||
# Uses flock to prevent multiple instances (#42)
|
||||
|
||||
SCRIPT_PATH="/var/www/html/bin/collect_metrics.php"
|
||||
LOG_FILE="/var/log/metrics_monitor.log"
|
||||
PID_FILE="/var/run/collect_metrics.pid"
|
||||
LOCK_FILE="/var/run/collect_metrics.lock"
|
||||
|
||||
log_message() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Use flock to prevent multiple monitor instances
|
||||
exec 200>"$LOCK_FILE"
|
||||
if ! flock -n 200; then
|
||||
log_message "Another monitor instance is running, exiting"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if the process is running
|
||||
is_running() {
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
@@ -22,6 +31,12 @@ is_running() {
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# Also check if any collect_metrics.php is running (catches orphan processes)
|
||||
if pgrep -f "collect_metrics.php" > /dev/null 2>&1; then
|
||||
# Update PID file with actual PID
|
||||
pgrep -f "collect_metrics.php" | head -1 > "$PID_FILE"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user