Last active
November 15, 2022 21:21
-
-
Save xpepper/c1a87d2e3ce855815286281432eff7e0 to your computer and use it in GitHub Desktop.
Print the db connection count for an AWS RDS db
This file contains 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
#!/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