AWS-CLoud Watch - Notes By ShariqSP
AWS CloudWatch Overview
What is AWS CloudWatch?
AWS CloudWatch is a monitoring and observability service provided by Amazon Web Services. It allows users to collect and track metrics, collect and monitor log files, set alarms, and automatically react to changes in AWS resources. CloudWatch provides insights into the performance and health of your AWS infrastructure and applications.
Why do we need AWS CloudWatch?
AWS CloudWatch is essential for:
- Monitoring the performance of AWS resources
- Detecting and troubleshooting issues in real-time
- Setting alarms to notify when certain thresholds are breached
- Automating actions based on predefined metrics or events
- Analyzing logs to gain insights into application behavior
- Optimizing resource utilization and cost management
How to Access AWS CloudWatch?
You can access AWS CloudWatch through the AWS Management Console, AWS CLI (Command Line Interface), AWS SDKs (Software Development Kits), or AWS CloudWatch API (Application Programming Interface).
- AWS Management Console: Log in to the AWS Management Console, navigate to the CloudWatch service, and explore metrics, alarms, logs, and dashboards.
- AWS CLI: Use AWS CLI commands to interact with CloudWatch programmatically, such as retrieving metrics, setting alarms, or querying log data.
- AWS SDKs: Integrate CloudWatch functionality into your applications using AWS SDKs available for various programming languages.
- AWS CloudWatch API: Develop custom applications or scripts to interact with CloudWatch using the API endpoints provided by AWS.
Examples on Monitoring an EC2 Instance
Here are step-by-step examples on how to monitor an EC2 instance using AWS CloudWatch:
Monitoring CPU Utilization
To monitor CPU utilization of an EC2 instance:
- Log in to the AWS Management Console.
- Navigate to the CloudWatch service.
- Click on "Alarms" in the left navigation pane.
- Click on "Create Alarm".
- Under "Select metric", choose "EC2" as the namespace and select the "Per-Instance Metrics" tab.
- Select the desired EC2 instance from the list.
- Choose the "CPUUtilization" metric.
- Configure the threshold for CPU utilization that triggers the alarm.
- Specify the actions to be taken when the alarm state is triggered. Choose "In alarm", then select "Stop instance" action to stop the instance.
- Configure the notification actions. Choose "In alarm", then select "Send notification to an SNS topic" and select the SNS topic to send the notification.
- Complete the alarm configuration and click "Create Alarm".
Monitoring Disk Utilization
To monitor disk utilization of an EC2 instance:
- Follow steps 1-7 from the CPU utilization monitoring section.
- Choose the "Disk" metric.
- Configure the threshold for disk utilization that triggers the alarm.
- Specify the actions to be taken when the alarm state is triggered. Choose "In alarm", then select "Stop instance" action to stop the instance.
- Configure the notification actions. Choose "In alarm", then select "Send notification to an SNS topic" and select the SNS topic to send the notification.
- Complete the alarm configuration and click "Create Alarm".
Monitoring Network Utilization
To monitor network utilization of an EC2 instance:
- Follow steps 1-7 from the CPU utilization monitoring section.
- Choose the "Network" metric.
- Configure the threshold for network utilization that triggers the alarm.
- Specify the actions to be taken when the alarm state is triggered. Choose "In alarm", then select "Stop instance" action to stop the instance.
- Configure the notification actions. Choose "In alarm", then select "Send notification to an SNS topic" and select the SNS topic to send the notification.
- Complete the alarm configuration and click "Create Alarm".
Conclusion
Monitoring EC2 instances with AWS CloudWatch provides valuable insights into their performance and health. By tracking metrics such as CPU utilization, disk utilization, and network utilization, you can optimize resource usage, troubleshoot issues, and ensure the smooth operation of your applications running on EC2 instances. Implementing actions like instance stoppage and email notifications enhances your ability to proactively manage your AWS resources.