Day-16-Aws
Understanding AWS CloudWatch: A Comprehensive Guide with Live Demos
TLDR: This blog post provides an in-depth exploration of AWS CloudWatch, detailing its functionalities, features, and practical applications through two live demonstrations focused on CPU utilization and custom metrics. It emphasizes the importance of hands-on experience for mastering AWS services and preparing for real-world scenarios.
In this blog post, we will dive deep into AWS CloudWatch, a vital service for monitoring and managing AWS resources. This post is structured to provide both theoretical insights and practical demonstrations, ensuring a comprehensive understanding of CloudWatch's capabilities.
CloudWatch → GateKeeper / watchman to cloud |
what activities are happening in cloud → who is entering the cloud and who is creating resource in cloud |
→ so CloudWatch (activities are happening in cloud) + lambada fn (perform certain action) → cost optimization |
→ so CloudWatch (activities are happening in cloud→ cpu utilization more than 80%) + auto scaling (auto scale ec2) → Scaling |
Feature | Usage |
Monitoring | continuously monitors AWS resources and applications → real-time metrics |
Metrics | quantitative data about your AWS resources (collect information of resources) → CPU utilization, memory usage, and API request counts → crucial for effective resource management. |
Alaram | trigger notifications based on specific metric thresholds → eg : CPU utilization exceeds a certain percentage (> 80 %)→ an alarm can notify to take action |
Logs insight | who accessed which resources and when → security and compliance monitoring |
Custom Metrics | |
Cost Optimization | Lambada fn → monitoring resource usage and helping identify underutilized resources → scaling based on demand |
Scaling | cpu utilization more than 80% → notify to auto scaling group |
Logs |
created project inside codeBuild → cloudwatch keep tack of codebuild → so now it consist of all logs —> whether it is run successfully or failed to run |
search → cloudWatch → logs(sidebar) → log groups (automatically tracks logs) |
click on project → log stream (tab) [consist of all log → whether it is run successfully or failed to run → with timestamp] → click on single log → log events (page) → consist of all message |
Metrics |
search → cloudWatch → metrics(sidebar) → all metrics (automatically tracks metric) |
browse (tab) [consist of cards →ec2,s3 …] → ec2 [consist of cards(metrics)→ auto scaling group, AMI id, Pre-instance metric, ….] → Pre-instance metric → table (instance id , metric name) |
browse (tab) [consist of cards →ec2,s3 …] → ec2 →dashboard |
metric demo |
create ec2 instance → with enable public ip |
cpu_skipe.py → increase or decrease cpu usage on ec2 instance |
login to ec2 → ssh -i aws_login.pem ubuntu@<public-ip> |
top → to check cpu utilization in ec2 |
search → cloudWatch → metrics(sidebar) → all metrics (automatically tracks metric) → browse (tab) [consist of cards →ec2,s3 …] → ec2 [consist of cards(metrics)→ auto scaling group, AMI id, Pre-instance metric, ….] → Across All instance metric → metric name → select CPU utilization |
search → ec2 → instance → selected created instance → Monitoring (tab) → Manage detailed monitoring → (checked) detailed monitoring → confirm (normally monitoring data is send every 5min , but now after enabling detailed monitoring ,monitoring data is send every 1min) |
nano cpu_skipe.py → paste the code from github → save the file |
python3 cpu_skipe.py |
search → cloudWatch → metrics(sidebar) → all metrics (automatically tracks metric) → Graphed metric (tab) →( statistic : Average → period : 15min ) |
cpu usage >= 50% → 5min → then send notification to devops/Sre team by email→ Alaram option in cloudwatch |
search → cloudWatch → alarm(sidebar) → in alarm → create alarm →select metric → browse (tab) [consist of cards →ec2,s3 …] → ec2 → Pre-instance metric → table (instance id: above created ec2 instance id , metric name : CPU utilization) → select metric |
instance id: above created ec2 instance id , metric name : CPU utilization , stastics : average , period : 5min |
condition → static >= 50% —> next |
Notification → state trigger: in alarm , send notification by SNS topic : create a new topic (name : , email: test@gamil.com → create topic ) —> next |
message in notification send to above mention email →(name: , message: ) → next |
goto gmail → test@gamil.com → confirm the aws notification to alarm (spam,promotion folder) |
What is AWS CloudWatch?
AWS CloudWatch can be thought of as a gatekeeper for your AWS cloud environment. It monitors various activities and resources, providing insights into performance and operational health. Just like a watchman keeps an eye on a property, CloudWatch tracks the activities happening within your AWS account, allowing you to query and analyze these activities.
Key Functions of CloudWatch
Monitoring: CloudWatch continuously monitors AWS resources and applications, providing real-time metrics.
Alarming: It allows users to set alarms based on specific metrics, notifying them when thresholds are crossed.
Logging: CloudWatch logs activities, enabling users to review actions taken on their resources.
Reporting: It generates reports based on the collected data, helping in performance analysis and optimization.
Features of AWS CloudWatch
1. Metrics
Metrics are fundamental to CloudWatch. They provide quantitative data about your AWS resources. For example, metrics can include CPU utilization, memory usage, and API request counts. Understanding these metrics is crucial for effective resource management.
2. Alarms
Alarms in CloudWatch are used to trigger notifications based on specific metric thresholds. For instance, if CPU utilization exceeds a certain percentage, an alarm can notify the relevant personnel to take action.
3. Log Insights
CloudWatch can log activities automatically, providing insights into who accessed which resources and when. This feature is essential for security and compliance monitoring.
4. Custom Metrics
While CloudWatch tracks many default metrics, it also allows users to create custom metrics tailored to their specific applications and needs. This flexibility is crucial for comprehensive monitoring.
5. Cost Optimization and Scaling
CloudWatch plays a significant role in cost optimization by monitoring resource usage and helping identify underutilized resources. It also integrates with other AWS services to facilitate scaling based on demand.
Practical Demonstrations
In this section, we will conduct two live demonstrations to illustrate the functionalities of AWS CloudWatch.
Demo 1: Monitoring EC2 CPU Utilization
In this demonstration, we will set up an alarm for an EC2 instance to monitor its CPU utilization. The steps include:
Creating an EC2 Instance: Launch a new EC2 instance and ensure it is running.
Setting Up CloudWatch: Navigate to the CloudWatch service in the AWS Management Console.
Creating an Alarm: Set an alarm to trigger when CPU utilization exceeds 50%.
Simulating Load: Use a Python script to simulate CPU load and observe how CloudWatch tracks this metric.
Receiving Notifications: Configure notifications via email to alert when the alarm is triggered.
Demo 2: Custom Metrics
The second demonstration will focus on creating and monitoring custom metrics. This will involve:
Defining Custom Metrics: Understanding how to define and send custom metrics to CloudWatch.
Monitoring Application Performance: Using these metrics to monitor specific application performance indicators.
Setting Alarms for Custom Metrics: Similar to the first demo, we will set alarms based on these custom metrics.
Conclusion
AWS CloudWatch is an essential tool for anyone working with AWS services. Its ability to monitor, log, and alert on various metrics makes it invaluable for maintaining operational health and performance. By engaging in hands-on demonstrations, users can gain practical experience that is crucial for real-world applications and interviews.
For those looking to deepen their understanding, I encourage you to explore the AWS CloudWatch documentation and experiment with the features discussed in this post. Remember, practical experience is key to mastering AWS services.