Created
September 8, 2022 18:15
-
-
Save tangoslee/7da9cbfdbf97e8a9dd77fe085849bdb5 to your computer and use it in GitHub Desktop.
[AWS] Simple MySQL connection monitoring for CloudWatch
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
#!/bin/sh | |
MYSQL="mysql" | |
max_connections=$(mysql -e "show variables like 'max_connections'" 2>/dev/null | grep -i "max_connections" | awk '{print $2}') | |
threads_connected=$(mysqladmin extended-status | grep -i 'threads_connected' | awk '{ print $4}') | |
cdate=$(date -u +%Y-%m-%dT%H:%M:00.000Z) | |
instanceid="${INSTANCE_ID}" | |
aws cloudwatch put-metric-data --metric-name MySQLMaxConnections --namespace "CustomMySQLMetrics" --dimensions="InstanceId=$instanceid" --value $max_connections --timestamp $cdate | |
aws cloudwatch put-metric-data --metric-name MySQLThreadsConnected --namespace "CustomMySQLMetrics" --dimensions="InstanceId=$instanceid" --value $threads_connected --timestamp $cdate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment