Cloudwatch
Cloudwatch Metrics
Cloudwatch
provide metrics for everyAWS Service
Metrics
is a variable to monitor, such as- CPU Utilization
- Networking data
Metric
belong toNamespace
Namespace
are similar toGroup
Metric
dimensions areAttribute
, like- Instance ID
- Environment Name
- Each
Metric
can have up to10 Dimensions
Metrics
haveTimestamps
- Using
metric
, theCloudwatch Dashboard
is generated
Cloudwatch Detailed Monitoring
- By default,
EC2
have 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 Graph
includes differentRegion
Dashboard Graph
includes 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
Cloudwatch
throughSDK
Cloudwatch
collect 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
S3
to store or archive- Stream to
Elastic Search
for 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
KMS
can 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 Store
to 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 itsOK
orALARM
state)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 recentPeriod
to consider to generate a alarm stateDataPoints To Alarm
: Determine to go toALARM
state. 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 Pipeline
state change - Can trigger
- Lambda Function
- SQS
- SNS
- Kinesis
Cloudwatch Event
create a sample document to give information about the change- Use case in
S3
andCode Pipeline
Code
can be uploaded toS3
Cloudwatch Event
trigger theCode Pipeline
Code
will be deployed to theElastic Beanstalk
- Can be used to change the number of
Fargate Cluster
should 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