Add show-ram.sh script to show RAM usage per node
Shows RAM usage for all containers in a compose file with total. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
53
show-ram.sh
Executable file
53
show-ram.sh
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Show RAM usage for containers in a compose file
|
||||||
|
# Usage: ./show-ram.sh <compose-file-name>
|
||||||
|
# Example: ./show-ram.sh ethereum-mainnet-geth-archive
|
||||||
|
|
||||||
|
BASEPATH="$(dirname "$0")"
|
||||||
|
COMPOSE_NAME="$1"
|
||||||
|
|
||||||
|
if [ -z "$COMPOSE_NAME" ]; then
|
||||||
|
echo "Usage: ./show-ram.sh <compose-file-name>"
|
||||||
|
echo "Example: ./show-ram.sh ethereum-mainnet-geth-archive"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPOSE_FILE="${BASEPATH}/${COMPOSE_NAME}.yml"
|
||||||
|
|
||||||
|
if [ ! -f "$COMPOSE_FILE" ]; then
|
||||||
|
echo "Error: Compose file not found: $COMPOSE_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get container IDs for this compose project
|
||||||
|
CONTAINER_IDS=$(docker compose -f "$COMPOSE_FILE" ps -q 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$CONTAINER_IDS" ]; then
|
||||||
|
echo "No running containers found for $COMPOSE_NAME"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "RAM usage for $COMPOSE_NAME:"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
|
||||||
|
# Show stats for each container
|
||||||
|
docker stats --no-stream --format "{{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}" $CONTAINER_IDS
|
||||||
|
|
||||||
|
echo "----------------------------------------"
|
||||||
|
|
||||||
|
# Calculate total
|
||||||
|
total_mib=$(docker stats --no-stream --format "{{.MemUsage}}" $CONTAINER_IDS | \
|
||||||
|
awk -F'/' '{
|
||||||
|
val=$1;
|
||||||
|
gsub(/[^0-9.]/,"",val);
|
||||||
|
if($1 ~ /GiB/) val*=1024;
|
||||||
|
sum+=val
|
||||||
|
} END {printf "%.0f", sum}')
|
||||||
|
|
||||||
|
if [ "$total_mib" -ge 1024 ]; then
|
||||||
|
total_gib=$(echo "scale=2; $total_mib / 1024" | bc)
|
||||||
|
echo "Total: ${total_gib} GiB"
|
||||||
|
else
|
||||||
|
echo "Total: ${total_mib} MiB"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user