80 lines
2.9 KiB
Bash
Executable File
80 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
env_file="${1:-${repo_root}/compose/.env}"
|
|
infra_compose="${repo_root}/compose/docker-compose.infra.yml"
|
|
backend_compose="${repo_root}/compose/docker-compose.backend.yml"
|
|
admin_compose="${repo_root}/compose/docker-compose.admin.yml"
|
|
|
|
if [[ ! -f "$env_file" ]]; then
|
|
echo "Environment file not found: $env_file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
section() {
|
|
printf '\n## %s\n' "$1"
|
|
}
|
|
|
|
read_value() {
|
|
local key="$1"
|
|
sed -n "s/^${key}=//p" "$env_file" | head -n 1
|
|
}
|
|
|
|
infra_project="$(read_value COMPOSE_PROJECT_NAME)"
|
|
backend_project="$(read_value BACKEND_COMPOSE_PROJECT_NAME)"
|
|
admin_project="$(read_value ADMIN_COMPOSE_PROJECT_NAME)"
|
|
|
|
if [[ -z "$infra_project" || -z "$backend_project" || -z "$admin_project" ]]; then
|
|
echo "Compose project names are missing from the environment file." >&2
|
|
exit 1
|
|
fi
|
|
|
|
section "Runtime snapshot"
|
|
bash "${repo_root}/scripts/capture-runtime-snapshot.sh"
|
|
|
|
section "Application containers"
|
|
docker compose --project-name "$infra_project" --env-file "$env_file" -f "$infra_compose" ps --all
|
|
docker compose --project-name "$backend_project" --env-file "$env_file" -f "$backend_compose" ps --all
|
|
docker compose --project-name "$admin_project" --env-file "$env_file" -f "$admin_compose" ps --all
|
|
|
|
section "Container resource totals"
|
|
docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}'
|
|
|
|
section "PostgreSQL database statistics"
|
|
docker compose --project-name "$infra_project" --env-file "$env_file" -f "$infra_compose" exec -T postgres sh -ec '
|
|
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -P pager=off -c "
|
|
SELECT datname,
|
|
numbackends,
|
|
xact_commit,
|
|
xact_rollback,
|
|
blks_read,
|
|
blks_hit,
|
|
temp_files,
|
|
temp_bytes,
|
|
deadlocks,
|
|
pg_database_size(datname) AS size_bytes
|
|
FROM pg_stat_database
|
|
WHERE datname IN (current_database(), '\''mlkj_admin'\'')
|
|
ORDER BY datname;"
|
|
'
|
|
|
|
section "PostgreSQL connection states"
|
|
docker compose --project-name "$infra_project" --env-file "$env_file" -f "$infra_compose" exec -T postgres sh -ec '
|
|
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -P pager=off -c "
|
|
SELECT datname, state, wait_event_type, count(*)
|
|
FROM pg_stat_activity
|
|
WHERE datname IS NOT NULL
|
|
GROUP BY datname, state, wait_event_type
|
|
ORDER BY datname, state, wait_event_type;"
|
|
'
|
|
|
|
section "Redis statistics"
|
|
docker compose --project-name "$infra_project" --env-file "$env_file" -f "$infra_compose" exec -T redis sh -ec '
|
|
redis-cli --no-auth-warning -a "$REDIS_PASSWORD" INFO clients memory stats persistence |
|
|
grep -E "^(connected_clients|blocked_clients|used_memory:|used_memory_peak:|mem_fragmentation_ratio:|total_connections_received:|total_commands_processed:|instantaneous_ops_per_sec:|keyspace_hits:|keyspace_misses:|evicted_keys:|expired_keys:|rdb_last_bgsave_status:|aof_enabled:)"
|
|
'
|
|
|
|
section "Docker disk usage"
|
|
docker system df
|