Bootstrap FreeKB - Amazon Web Services (AWS) - Create ElastiCache Redis high Connections Cloudwatch Alarm using the AWS CLI
Amazon Web Services (AWS) - Create ElastiCache Redis high Connections Cloudwatch Alarm using the AWS CLI


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

Cloudwatch alarms can be used to do something, such as:

When some conditiion is met, such as:

If you have not yet created and subscribed to a Simple Notifcation Service (SNS) topic, check out my article Create Simple Notification Service (SNS) Topics using the AWS CLI. Assuming you have created and subscribed to a Simple Notifcation Service (SNS) topic, the aws sns list-topics command can be used to list your topics. 

~]$ aws sns list-topics
{
    "Topics": [
        {
            "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"
        }
    ]
}

 

The aws ec2 describe-instances command can be used to list your EC2 instances. Something like this should be returned.

~]# aws ec2 describe-instances 
{
    "Reservations": [
        {
            "Instances": [
                {
                    "InstanceId": "i-01234475cf14abcde",

 

Now that you have the Amazon Resource Number (ARN) of one of your Simple Notification Service (SNS) Topic and the ID of one of your EC2 instances, you can use the aws cloudwatch put-metric-alarm command to create a new cloudwatch alarm. This will not do anything with the EC2 instance. This will just create an alarm.

  • Period and Evaluation Periods and Datapoints to Alarm are used to set the Alarm State, such as In Alarm. In this example:
    • --period 300 means that the Redis Cache Cluster will be checked once every 300 seconds
    • --datapoints-to-alarm 1 means there only needs to be a single occurrence where there are 1000 or more connections for the alarm state to be set to In Alarm. This works in conjunction with Comparison Operator and Threshold and Unit. In this example, the combination of --comparison-operator  GreaterThanThreshold and --threshold 1000.0 and --unit Maximum means that the evaulation is True when there are 1000 or more connections
    • --evaulation-periods 1 means only the current occurence is evaluated to determine if the alarm state should be updated
  • A message will be published to your Simple Notification Service (SNS) Topic if there are more than 1000 connections or if the Alarm has INSUFFICIENT_DATA.

It is also noteworthy that if Datapoints to Alarm were 2 and Evaluation Periods were 10, then the alarm state would be set to In Alarm if there are more than 1000 connections in 2 of the last 10 periods.

aws cloudwatch put-metric-alarm \
--alarm-name redis-connections \
--alarm-description "Alarm when redis exceeds 1000 connections" \
--namespace AWS/ElastiCache \
--metric-name CurrConnections \
--comparison-operator GreaterThanThreshold \
--threshold 1000.0 \
--statistic Maximum \
--period 300 \
--evaluation-periods 1 \
--treat-missing-data missing \
--datapoints-to-alarm 1 \
--dimensions "Name=clusterId,Value=<your Redis Cache Cluster ID goes here, e.g. my-redis-cluster>" \
--alarm-actions <the ARN of your SNS topic>
--insufficient-data-actions <the ARN of your SNS topic>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 299253 in the box below so that we can be sure you are a human.