Monitoring with AWS CloudWatch🚨

Bhargav Teja
3 min readMay 27, 2024

--

What is CloudWatch Monitoring? 🤔

CloudWatch Monitoring is a service provided by AWS to monitor your cloud resources and applications. It helps you keep an eye on your resource usage, such as CPU load, and set up alarms to notify you via email 📧 when certain thresholds are exceeded. This ensures that you are promptly alerted to potential issues, allowing you to take timely actions to maintain the performance and reliability of your applications.

How to Create Alarms in AWS CloudWatch 🚨

Creating alarms in AWS CloudWatch is a straightforward process. Follow these steps to set up an alarm that monitors CPU utilization on an EC2 instance and notifies you via email if the CPU usage exceeds a certain limit:

1. Open CloudWatch: 🔍
— In the AWS Management Console, search for “CloudWatch” and select it.

2. Navigate to Alarms: 📊
— In the CloudWatch dashboard, go to the “Alarms” section and click on “All alarms.”

3. Create a New Alarm: ➕
— Click on “Create Alarm.”
— Select “Select metric” to choose the metric you want to monitor.

4. Choose EC2 Metrics: 📈
— Under “Browse,” select “EC2” and then choose “Per-Instance Metrics.”
— Locate and select the EC2 instance you want to monitor by its instance ID.
— Choose “CPUUtilization” as the metric to monitor.

5. Configure Alarm Conditions: ⚙️
— Set the period to 5 minutes.
— Specify the threshold. For example, set it to “Greater than or equal to 50%.” This means the alarm will trigger if the CPU usage exceeds 50%.

6. Set Up Notifications: 📬
— Go to the “Notification” tab.
— Under “In alarm,” choose to create a new topic.
— Provide a name for the topic and enter the email address where notifications should be sent.
— Create the topic and proceed to create the alarm.

7. Confirm Subscription: ✅
— You will receive an email to confirm the subscription to the notification topic. Open the email and confirm the subscription.

Monitoring Your EC2 Instance 🖥️

To monitor your EC2 instance’s CPU load and running processes, you can use the terminal commands:

- top: This command displays the system’s running processes and CPU load averages.
- ps -ef: This command shows a detailed list of all running processes, including their process IDs (PID) and parent process IDs (PPID).

Stress Testing Your CPU 🧪

To test the CPU load and see if your alarm works, you can use a tool called `stress`. Here’s how to install and use it:

  1. Install stress: 🛠️
sudo apt install stress -y

2. Run stress: 🏋️

stress --cpu 4 --timeout 60s

This command stresses the CPU with 4 workers for 60 seconds.

Receiving Alerts 📲

Once the CPU load crosses the threshold set in your alarm, CloudWatch will send an alert to your email. This ensures you are aware of high CPU usage and can take necessary actions to manage your resources effectively.

By following these steps, you can easily set up monitoring and alerts for your AWS resources using CloudWatch, ensuring your applications run smoothly and efficiently.

--

--

Bhargav Teja

🚀 DevOps Intern passionate about 🐧 Linux, ☁️ AWS, 🔧 Terraform, 🛠️ Azure DevOps, 🐳 Docker, 🗂️ Git, and 💻 Bash scripting.