> For the complete documentation index, see [llms.txt](https://huy312100.gitbook.io/software-development/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huy312100.gitbook.io/software-development/cloud-service/aws/certificate/clf-c02/cloud-technology-and-services/cloud-monitoring/cloudwatch.md).

# CloudWatch

### Overview

• CloudWatch provides metrics for every service in AWS

• Metric is a variable to monitor (CPUUtilization, NetworkIn...)

• Metrics have timestamps

• Can create CloudWatch dashboards of metrics

Example: CloudWatch Billing metric

<figure><img src="https://1722711354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwNXdoUkfmcozr29fRrfb%2Fuploads%2FYhZXsue8KgJPyXu052yR%2FScreenshot%202023-12-24%20at%2000.24.14.png?alt=media&amp;token=be517bf8-50bc-4593-95f7-b0530c976046" alt=""><figcaption></figcaption></figure>

### Important Metrics

• EC2 instances: CPU Utilization, Status Checks, Network (not RAM)

* Default metrics every 5 minutes
* Option for Detailed Monitoring ($$$): metrics every 1 minute

• EBS volumes: Disk Read/Writes

• S3 buckets: BucketSizeBytes, NumberOfObjects, AllRequests

• Billing: Total Estimated Charge (only in us-east-1)

• Service Limits: how much you’ve been using a service API

• Custom metrics: push your metrics

### CloudWatch Alarms

• Alarms are used to trigger notifications for any metric

• Alarms actions...

* Auto Scaling: increase or decrease EC2 instances “desired” count
* EC2 Actions: stop, terminate, reboot, or recover an EC2 instance
* SNS notifications: send a notification to an SNS topic

• Various options (sampling, %, max, min, etc...)

• Can choose the period on which to evaluate an alarm

• Example: create a billing alarm on the CloudWatch Billing metric

• Alarm States: OK. INSUFFICIENT\_DATA, ALARM

### CloudWatch Logs

• CloudWatch Logs can collect log from:

* Elastic Beanstalk: collection of logs from application
* ECS: collection from containers
* AWS Lambda: collection from function logs
* CloudTrail based on filter
* CloudWatch log agents: on EC2 machines or on-premises servers
* Route53: Log DNS queries

• Enables real-time monitoring of logs

• Adjustable CloudWatch Logs retention

### CloudWatch Logs for EC2

* By default, no logs from your EC2 instance will go to CloudWatch
* You need to run a CloudWatch agent on EC2 to push the log files you want
* Make sure IAM permissions are correct
* The CloudWatch log agent can be setup on-premises too

<figure><img src="https://1722711354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwNXdoUkfmcozr29fRrfb%2Fuploads%2FvmhuhZxn1MRkRNlGUvGZ%2FScreenshot%202023-12-24%20at%2000.27.53.png?alt=media&amp;token=6fde9658-89c7-4676-b0ce-2d1af48b0875" alt=""><figcaption></figcaption></figure>
