Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@xpepper
Last active November 15, 2022 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpepper/c1a87d2e3ce855815286281432eff7e0 to your computer and use it in GitHub Desktop.
Save xpepper/c1a87d2e3ce855815286281432eff7e0 to your computer and use it in GitHub Desktop.
Print the db connection count for an AWS RDS db
#!/usr/bin/env bash
export AWS_PAGER=""
db_connections () {
echo "## ${1}:"
aws cloudwatch get-metric-statistics \
--namespace AWS/RDS \
--dimensions Name=DBInstanceIdentifier,Value=$1 \
--metric-name DatabaseConnections \
--start-time $startTime \
--end-time $endTime \
--period 300 \
--statistics Maximum \
--output text --query 'Datapoints[*].[Timestamp,Maximum]'
}
dbInstance1=postgres-production-rds-1
dbInstance2=postgres-production-rds-2
daysAgoStart=${1:-90}
daysAgoEnd=${2:-0}
startTime=$(date -v-${daysAgoStart}M +"%Y-%m-%dT%H:%M:%S%Z")
endTime=$(date -v-${daysAgoEnd}M +"%Y-%m-%dT%H:%M:%S%Z")
echo "db connections from $startTime to $endTime"
db_connections $dbInstance1 | sort
db_connections $dbInstance2 | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment