forked from iam-veeramalla/aws-devops-zero-to-hero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4aa6af
commit 86d9246
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# AWS CLOUD WATCH | ||
|
||
Welcome back to our "30 Days AWS Zero to Hero" series. Today, on Day 16, we will deep dive into AWS CloudWatch. | ||
|
||
What is AWS CloudWatch? | ||
|
||
AWS CloudWatch is a powerful monitoring and observability service provided by Amazon Web Services. It enables you to gain insights into the performance, health, and operational aspects of your AWS resources and applications. CloudWatch collects and tracks metrics, collects and monitors log files, and sets alarms to alert you on certain conditions. | ||
|
||
Advantages of AWS CloudWatch: | ||
|
||
Comprehensive Monitoring: CloudWatch allows you to monitor various AWS resources such as EC2 instances, RDS databases, Lambda functions, and more. You get a unified view of your entire AWS infrastructure. | ||
|
||
Real-Time Metrics: It provides real-time monitoring of metrics, allowing you to respond quickly to any issues or anomalies that might arise. | ||
|
||
Automated Actions: With CloudWatch Alarms, you can set up automated actions like triggering an Auto Scaling group to scale in or out based on certain conditions. | ||
|
||
Log Insights: CloudWatch Insights lets you analyze and search log data from various AWS services, making it easier to troubleshoot problems and identify trends. | ||
|
||
Dashboards and Visualization: Create custom dashboards to visualize your application and infrastructure metrics in one place, making it easier to understand the overall health of your system. | ||
|
||
Problem Solving with AWS CloudWatch: | ||
|
||
CloudWatch helps address several critical challenges, including: | ||
|
||
Resource Utilization: Tracking resource utilization and performance metrics to optimize your AWS infrastructure efficiently. | ||
Proactive Monitoring: Identifying and resolving issues before they impact your applications or users. | ||
Troubleshooting: Analyzing logs and metrics to troubleshoot problems and reduce downtime. | ||
Scalability: Automatically scaling resources based on demand to ensure optimal performance and cost efficiency. | ||
|
||
Practical Use Cases of AWS CloudWatch: | ||
|
||
Auto Scaling: CloudWatch can trigger Auto Scaling actions based on defined thresholds. For example, you can automatically scale in or out based on CPU utilization or request counts. | ||
|
||
Resource Monitoring: Monitor EC2 instances, RDS databases, DynamoDB tables, and other AWS resources to gain insights into their performance and health. | ||
|
||
Application Insights: Track application-specific metrics to monitor the performance of your applications and identify potential bottlenecks. | ||
|
||
Log Analysis: Use CloudWatch Logs Insights to analyze log data, identify patterns, and troubleshoot issues in real-time. | ||
|
||
Billing and Cost Monitoring: CloudWatch can help you monitor your AWS billing and usage patterns, enabling you to optimize costs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from flask import Flask | ||
import time | ||
import random | ||
import boto3 | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
# Initialize AWS CloudWatch client | ||
cloudwatch = boto3.client('cloudwatch', region_name='us-east-1') | ||
|
||
# Sample product data for our online store | ||
products = { | ||
'1': {'name': 'Product 1', 'price': 10.99}, | ||
'2': {'name': 'Product 2', 'price': 19.99}, | ||
'3': {'name': 'Product 3', 'price': 5.49} | ||
} | ||
|
||
@app.route('/') | ||
def index(): | ||
start_time = time.time() | ||
|
||
# Simulate processing time | ||
time.sleep(random.uniform(0.1, 0.5)) | ||
|
||
# Log the page view metric to CloudWatch | ||
log_metric('PageViews', 1) | ||
|
||
# Log the response time metric to CloudWatch | ||
response_time = (time.time() - start_time) * 1000 | ||
log_metric('ResponseTime', response_time) | ||
|
||
return "Welcome to our Online Store!" | ||
|
||
@app.route('/product/<product_id>') | ||
def product(product_id): | ||
start_time = time.time() | ||
|
||
# Simulate processing time | ||
time.sleep(random.uniform(0.2, 0.8)) | ||
|
||
# Log the page view metric to CloudWatch | ||
log_metric('PageViews', 1) | ||
|
||
# Log the response time metric to CloudWatch | ||
response_time = (time.time() - start_time) * 1000 | ||
log_metric('ResponseTime', response_time) | ||
|
||
if product_id in products: | ||
return f"Product: {products[product_id]['name']}, Price: ${products[product_id]['price']}" | ||
else: | ||
return "Product not found." | ||
|
||
def log_metric(metric_name, value): | ||
# Send custom metric to CloudWatch | ||
cloudwatch.put_metric_data( | ||
Namespace='OnlineStore', | ||
MetricData=[{ | ||
'MetricName': metric_name, | ||
'Value': value, | ||
'Unit': 'Count' | ||
}] | ||
) | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
boto3 |