#!/bin/bash # Script to check memory status on Render # Usage: ./check_render_memory.sh [APP_URL] APP_URL=${1:-"http://localhost:5000"} MEMORY_ENDPOINT="$APP_URL/memory/render-status" echo "Checking memory status for application at $APP_URL" echo "Memory endpoint: $MEMORY_ENDPOINT" echo "-----------------------------------------" # Make the HTTP request HTTP_RESPONSE=$(curl -s "$MEMORY_ENDPOINT") # Check if curl command was successful if [ $? -ne 0 ]; then echo "Error: Failed to connect to $MEMORY_ENDPOINT" exit 1 fi # Pretty print the JSON response echo "$HTTP_RESPONSE" | python3 -m json.tool # Extract key memory metrics for quick display if command -v jq &> /dev/null; then echo "" echo "Memory Summary:" echo "--------------" MEMORY_MB=$(echo "$HTTP_RESPONSE" | jq -r '.memory_status.memory_mb') PEAK_MB=$(echo "$HTTP_RESPONSE" | jq -r '.memory_status.peak_memory_mb') STATUS=$(echo "$HTTP_RESPONSE" | jq -r '.memory_status.status') ACTION=$(echo "$HTTP_RESPONSE" | jq -r '.memory_status.action_taken') echo "Current memory: $MEMORY_MB MB" echo "Peak memory: $PEAK_MB MB" echo "Status: $STATUS" if [ "$ACTION" != "null" ]; then echo "Action taken: $ACTION" fi # Get trends if available if echo "$HTTP_RESPONSE" | jq -e '.memory_trends.trend_5min_mb' &> /dev/null; then TREND_5MIN=$(echo "$HTTP_RESPONSE" | jq -r '.memory_trends.trend_5min_mb') echo "" echo "5-minute trend: $TREND_5MIN MB" if (( $(echo "$TREND_5MIN > 5" | bc -l) )); then echo "⚠️ Warning: Memory usage increasing significantly" elif (( $(echo "$TREND_5MIN < -5" | bc -l) )); then echo "✅ Memory usage decreasing" else echo "✅ Memory usage stable" fi fi else echo "" echo "For detailed memory metrics parsing, install jq: 'brew install jq' or 'apt-get install jq'" fi