Sunday, March 20, 2022

AWS - Cloud Watch

CloudWatch:- Monitoring service on the basis of metrics

States of Alarm

In Alarm: - If the metric value is greater than a threshold value. Eg if you have set the threshold value of CPU utilization is > 50 and if EC2 instance CPU usage is > 50 then it is In Alarm State.

OK: If the metric value is less than a threshold value

Insufficient data: If the data which is collected by CloudWatch is not sufficient to determine the alarm then it is in an insufficient state.

EC2 Actions: These actions are performed on selected EC2 instances if an Alarm is triggered.

  • Stop 
  • Terminate 
  • Reboot

Step 1: Select CloudWatch Service.

Step 2: Click on Create Alarm Button

Step 3: Click on Metrics

Step 4: Select EC2 instance because we are monitoring EC2 instance.

Step 5: Click on Per instance Metrics

Step 6: Copy Instance Id in the search box

Step 7: Select Instance Id and Metric as CPU Utilization.

Step 8 Click on Select Metric Button.

Step 9: Keep all the properties same except below

            Threshold Type: Static

             Select : Greater Than (you can chose any option like >=,< etc)

            than : 50 ( I am selecting 50 so that I need to set the alarm if Cpu utilization is more than 50% of selected EC2 instance)

Click on Next Button.

Step 10 : Select In Alarm

Step 11 : Select SNS topic for notificaiton.

Step 12: Select EC2 Action and select Terminate Instance.

Step 13: Click on Next Button

Step 14: Give the Alarm Name and Click on Create Alarm Button.            

CloudWatch Log Monitoring

Step 1: Configure your IAM role or user for CloudWatch Logs

             Create a Role (Cloudwatchrole) for EC2 instance

             Attach Cloudwatch Full Access permission

             Add Role to Existing EC2 instance

Step 2: Install and configure CloudWatch Logs on an existing Amazon EC2 instance

            Connect to EC2 instance

            sudo yum update -y

           sudo yum install -y awslogs

           If required change /etc/awslogs/awslogs.conf to monitor the file. I am not changing anything in this file because I am monitoring /var/logs/messages file.

           By default, the /etc/awslogs/awscli.conf points to the us-east-1 Region. To push your logs to a different Region, edit the awscli.conf file and specify that Region.

            sudo systemctl start awslogsd

            sudo systemctl enable awslogsd.service 


Post a Comment