AWS RDS:如何获取当前 Activity / 连接数?

AWS RDS: How to get hold of the Current Activity / Number of Connections?

使用 AWS RDS 控制台可以很容易地在 "Current Activity" 列中查看实例的连接数:

如何从 aws cli 获取此信息?据我所知,aws rds describe-db-instances 似乎没有这条特定的信息。

注意:为了我的目的,知道是否有 any 连接就足够了。

对于指标,您应该使用 aws cloudwatch 工具。要获取当前的数据库连接数,你可以使用这样的东西:

aws cloudwatch get-metric-statistics --namespace AWS/RDS
--metric-name DatabaseConnections --start-time 2018-06-14T16:00:00Z
--end-time 2018-06-14T16:01:00Z --period 60 --statistics "Maximum"
--dimensions Name=DBInstanceIdentifier,Value=your-db-identifier

您需要将其与代码或脚本结合使用以插入正确的 --start-time--end-time 值。

mon-get-stats --region "your-region" --metric-name="DatabaseConnections" --namespace="AWS/RDS" --dimensions="DBInstanceIdentifier=your-db-name" --statistics Maximum > your-db-name.txt

awk 'END{printf "%.0f",}' your-db-name.txt > your-db-name-final.txt

echo "$(cat your-db-name-final.txt)"

以上小脚本显示您的 RDS 当前连接