Cloudwatch
Cloudwatch Metrics
Cloudwatchprovide metrics for everyAWS ServiceMetricsis a variable to monitor, such as- CPU Utilization
- Networking data
Metricbelong toNamespaceNamespaceare similar toGroupMetricdimensions areAttribute, like- Instance ID
- Environment Name
- Each
Metriccan have up to10 Dimensions MetricshaveTimestamps- Using
metric, theCloudwatch Dashboardis generated
Cloudwatch Detailed Monitoring
- By default,
EC2have metrics each5 minutes - With
Detailed Monitoring - Metric generate every
1 Minute - Good for
ASG - Free Tier allows
10 Detail Monitoring - For
EC2 Memory Usage, there is no default metric. Need to useCustom Metric
Cloudwatch Custom Metric
- Can send custom metrics to
Cloudwatch - Ability to send Dimension
- instance.id
- environment.name
- Metric Resolution
- Standard
1 Minute - High Resolution, up to
1 Sec - To send custom metric use
PutMetricData
Cloudwatch Dashboard
- Dashboard are
Global(cross region, cross account) Dashboard Graphincludes differentRegionDashboard Graphincludes differentAccount- Can setup
Auto Refresh - Pricing
- 3 Dashboard (Up to 50 Metrics) free
- After free tier,
3 dollar/dashboard/per month
Cloudwatch Logs
- Logs can be send to
CloudwatchthroughSDK Cloudwatchcollect log from- Elastic Beanstalk
- ECS
- AWS Lambda
- VPC Flow Logs
- API Gateway
- Cloudtrail
- Cloudwatch Log Agent (From
EC2 Instance) - Route 53 (DNS Query)
- Logs go to
S3to store or archive- Stream to
Elastic Searchfor analytics - Log Storage Architecture
- Groups: Log is grouped under name
- Each group has streams of logs
- Can define expiration period (After the expiration period, the logs will be deleted)
- Encryption
KMScan be used to encrypt the logs- Encryption is done in log group level
- Using encryption key, both new (create-log-group) and existing (associate) log group can be encrypted
- Encryption operation can be done only by CLI or SDK
- To send logs, make sure the
Permission to write logs are set - To follow/tail logs, we can use
AWS CLI - Possible to filter by expression
- Helpful to find logs or specific IP
- Can use to trigger alarm
Cloudwatch Logs Insights- Can be used to query logs
- To use, need to install the
Unified Cloudwatch Logs Event
Cloudwatch Logs Agent Vs Unified Agent
Logs Agent
- Old Version
Unified Agent
- Newer version
- Get Additional system level metrics
- Can use
SSM Parameter Storeto centralized configuration
Cloudwatch Alarms
- Alarms are used to trigger notification for any metric
- Alarms can go to
- ASG
- EC2 Actions
- SNS Notifications
- Alarm can raise
- Sampling value
- Percentage value
- Max or Min value
- Alarm States
OK(When everything is alright)INSUFFICIENT_DATA(When not enough data to measure it itsOKorALARMstate)ALARM(When metrics reached theThreshold)- Period
- Time length to evaluate the metric
- In case of
High Resolution Metric, period can be10 sec
Creating Cloudwatch Event
While creating a cloudwatch event, we can set
Period: Define evaluation time in seconds.Evaluation Period/Number of Data Point: Known asData Point. Number of recentPeriodto consider to generate a alarm stateDataPoints To Alarm: Determine to go toALARMstate. We can define how many period can be reached within a evaluation period to go toALARM
Cloudwatch Event
- Can schedule
CRON Jobs Event Pattern- Rules on react a service doing something
- Example:
Code Pipelinestate change - Can trigger
- Lambda Function
- SQS
- SNS
- Kinesis
Cloudwatch Eventcreate a sample document to give information about the change- Use case in
S3andCode Pipeline Codecan be uploaded toS3Cloudwatch Eventtrigger theCode PipelineCodewill be deployed to theElastic Beanstalk- Can be used to change the number of
Fargate Clustershould run according to the events - Allow monitor jobs in the batch jobs
Cloudwatch Agent
- Collect system info and log files
- Can track memory, swap and disk space