File size: 1,866 Bytes
0a7f9b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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