Amazon CloudWatch
- This service montiors your Resources and applications on AWS in real time.
- Related AWS Services to Know with Cloudwatch
- Amazon SNS (Simple Notification Service)
- EC2 AutoScaling
- AWS Cloud Trail
- AWS VPC Flow log
- AWS Lambda
- AWS IAM
- Cloud Watch is a Repository of metrics, User can use Alarms and statistics over metrics to notify and to report
AWS Cloudwatch Terms to Understand
-
Namespace:
- Container for Cloudwatch metrci
- Metrics in different namespaces are isolated from each other.
-
Metric:
- Reprsent a datapoint with time series that is published
- Eg: CPU Utilization, Free RAM, Network Read Bytes, Disk IO
- Along with Standard metrics, users can create their own custom metrics.
- Cannot be deleted. If the metric doesn’t have a datapoint in last 15 months, then the metric gets deleted.
- Lets view all the metrics
-
Time Stamp: time associated with metric
- Metrics Retention: If Datapoints time stamp
- with a Period < 60 seconds => 3 hours
- with a Period = 60 seconds => 15 days
- with a Peroid = 300 seconds => 63 days
- with a period of 1 hour => 15 months (455 days)
- Metrics Retention: If Datapoints time stamp
-
Statistics: For the metric values collected, following statistics will be available
- Minimum
- Maximum
- Sum
- Average
-
Alarm: Alarm is some metric’s value over some period of time which needs some action to be taken. Examples for creating alarms. Each alarm will have some action that can be taken. Action could be sending email to admins to automatically reacting
- if the cpu utilization is greater than 90% for 10 minutes => Create an alarm to send email to Admin (Alarm => SNS)
- If the Network In Bytes for the period of 1 day is zero => Create an alarm to stop the ec2 machine (Alarm => Action (Stop Ec2))
- If the BucketSizeBytes has increased by 10% => Create an alarm which calls AWS Lambda (Python code) to sync the data to on-premise
Publishing custom metrics to Cloudwatch
- Refer Here for Implementable solution
- Official Docs
Simple Notifications Service (SNS)
- SNS is a service which manages the notifications (sending messages, emails )
- To understand SMS
- Publisher
- Topic
- Subscriber
- Create an SNS Topic
- Now add subscribers
- Publisher is who has to notify the information
EC2 Instance Monitoring and actions
- Enable Detailed montioring as shown below
- Lets create an alarm to stop the ec2 when cpu utilzation is greater that 70% for the period of 10 minutes
- For artificial load lets install stress
sudo apt-get update sudo apt-get install stress -y stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 100m -v
- Alarm will have state
- OK => Alarm condition is not met
- ALARM => Alarm Condition is met
- Insufficient => data points are insufficient to decide ok/alarm state
- Lets Create an Alarm to send email to <your email> when cpu utilization is greater than 60% for a period of 5 minutes
- Here Notification has to be sent, So we need to Understand SNS
- Here Notification has to be sent, So we need to Understand SNS