Created
June 11, 2025 05:17
-
-
Save maxwofford/003f2667eb5c31e220b62644d2b1c26b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to show Docker container resource usage with Coolify project names | |
# Usage: ./coolify_resources.sh [--watch] | |
if [ "$1" = "--watch" ] || [ "$1" = "-w" ]; then | |
# Continuous monitoring mode | |
watch -n 2 "$0" | |
exit 0 | |
fi | |
echo "Coolify Container Resource Usage" | |
echo "===============================" | |
printf "%-25s %-15s %-15s %-15s %-10s %s\n" "PROJECT" "CPU %" "MEMORY" "NET I/O" "BLOCK I/O" "CONTAINER" | |
echo "----------------------------------------------------------------------------------------" | |
# Get stats for all running containers | |
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" | tail -n +2 | while read line; do | |
# Parse docker stats output | |
container_id=$(echo "$line" | awk '{print $1}') | |
cpu_perc=$(echo "$line" | awk '{print $2}') | |
mem_usage=$(echo "$line" | awk '{print $3}') | |
net_io=$(echo "$line" | awk '{print $4}') | |
block_io=$(echo "$line" | awk '{print $5}') | |
if [ -n "$container_id" ]; then | |
# Get container name and coolify project | |
container_name=$(docker ps --format '{{.Names}}' -f id=$container_id 2>/dev/null) | |
coolify_project=$(docker inspect $container_id --format '{{index .Config.Labels "coolify.projectName"}}' 2>/dev/null | grep -v '^$\|<no value>') | |
# Use project name if available, otherwise container name | |
display_name="$container_name" | |
if [ -n "$coolify_project" ] && [ "$coolify_project" != "<no value>" ]; then | |
display_name="$coolify_project" | |
fi | |
# Truncate names if too long | |
if [ ${#display_name} -gt 24 ]; then | |
display_name="${display_name:0:21}..." | |
fi | |
if [ ${#container_name} -gt 35 ]; then | |
container_name="${container_name:0:32}..." | |
fi | |
printf "%-25s %-15s %-15s %-15s %-10s %s\n" "$display_name" "$cpu_perc" "$mem_usage" "$net_io" "$block_io" "$container_name" | |
fi | |
done | sort -k2 -nr # Sort by CPU usage descending | |
echo | |
echo "Usage:" | |
echo " $0 - Show current resource usage" | |
echo " $0 --watch - Continuous monitoring (updates every 2s)" | |
echo " $0 -w - Same as --watch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment