CloudWatch Metrics represents a time-ordered set of data points that are published to CloudWatch. Think of a metric as a variable to monitor, and the data points represent the values of that variable over time. For example, the CPU usage of a particular EC2 instance is one metric provided by Amazon EC2.
Basic metrics are 5 min intervals and free. Custom metrics are 1 min intervals and cost you extra.
Stored for 2 weeks
Only host level metrics such as below are available free
VM level metrics such as memory metrics are not available by default. Its a custom metric done by scripts run in EC2
A namespaceis a container for CloudWatch metrics. Metrics in different namespaces are isolated from each other, so that metrics from different applications are not mistakenly aggregated into the same statistics.
You can create CloudWatch Dashboards to customize your view of cloud watch metrics
CloudWatch Alarms feature allows you to watch CloudWatch metrics and to receive notifications when the metrics fall outside of the levels (high or low thresholds) that you configure. You can attach multiple Alarms to each metric and each alarm can have multiple actions.
A CloudWatch Alarm is always in one of three states: OK, ALARM, or INSUFFICIENT_DATA. When the metric is within the range that you have defined as acceptable, the Monitor is in the OK state. When it breaches a threshold it transitions to the ALARM state. If the data needed to make the decision is missing or incomplete, the monitor transitions to the INSUFFICIENT_DATA state.
Choose resource (EC2 or ELB or DynamoDB etc)
Threshold: Example: CPU utilization >= 70% for 2 out of 5 data points
Actions: Alarms watch metrics and execute one or more actions by
Publishing notifications to Amazon SNS topics. SNS can inturn deliver notifications using HTTP, HTTPS, SMS, Email, or an Amazon SQS queue.
By initiating Auto Scaling actions
Executing Resource specific actions (Reboot EC2 etc.).
The actions happen only on state transitions, and will not be re-executed if the condition persists for hours or days.
Multiple notifications/actions are allowed when an Alarm is triggered. You can send an email and do a scaling action and do a recovery action, all with single alarm.
You can also add alarms to dashboards.
CloudWatch Events Amazon CloudWatch Events (CWE) is a stream of system events describing changes in your AWS resources. The events stream augments the CloudWatch Metrics and Logs streams to provide a more complete picture of the health and state of your applications. You write declarative rules to associate events of interest with automated actions to be taken. Currently, Amazon EC2, Auto Scaling, and AWS CloudTrail are supported. Via AWS CloudTrail, mutating API calls (i.e., all calls except Describe*, List*, and Get*) across all services are visible in CloudWatch Events.
An event indicates a change in your AWS environment.
AWS resources can generate events when their state changes.
For example, Amazon EC2 generates an event when the state of an EC2 instance changes from pending to running
Update DNS with public ip after EC2 starts successfully
Amazon EC2 Auto Scaling generates events when it launches or terminates instances.
Your applications can emit custom events by using the PutEvents API, with a payload uniquely suited to your needs
You can also set up scheduled events that are generated on a periodic basis. For example you can reboot your EC2 every 24 hours.
A rule matches incoming events and routes them to targets for processing.
A single rule can route to multiple targets, all of which are processed in parallel.
Rules are not processed in a particular order. This enables different parts of an organization to look for and process the events that are of interest to them.
A rule can customize the JSON sent to the target, by passing only certain parts or by overwriting it with a constant.
A target processes events.
Targets can include Amazon EC2 instances, AWS Lambda functions, Kinesis streams, Amazon ECS tasks, Step Functions state machines, Amazon SNS topics, Amazon SQS queues, and built-in targets.
A target receives events in JSON format.
CloudWatch Logs You can use CloudWatch Logs to monitor, store, and access your log files from EC2, CloudTrail, Route 53, and other sources.
Monitor Logs from Amazon EC2 Instances in Real-time—You can use CloudWatch Logs to monitor applications and systems using log data.
example, CloudWatch Logs can track the number of errors that occur in your application logs (replace ELMAH) and send you a notification whenever the rate of errors exceeds a threshold you specify.
Monitor AWS CloudTrail Logged Events
Archive Log Data—You can use CloudWatch Logs to store your log data in highly durable storage.
You can change the log retention setting so that any log events older than this setting are automatically deleted.
Log Route 53 DNS Queries—You can use CloudWatch Logs to log information about the DNS queries that Route 53 receives.
You can use the CloudWatch Logs agent installer on an existing EC2 instance to install and configure the CloudWatch Logs agent.
After installation is complete, logs automatically flow from the instance to the log stream you create while installing the agent. The agent confirms that it has started and it stays running until you disable it.
In addition to using the agent, you can also publish log data using the AWS CLI, CloudWatch Logs SDK, or the CloudWatch Logs API.
The AWS CLI is best suited for publishing data at the command line or through scripts.
The CloudWatch Logs SDK is best suited for publishing log data directly from applications or building your own log publishing application.
CloudWatch retains metric data as follows:
Data points with a period of less than 60 seconds are available for 3 hours. These data points are high-resolution custom metrics.
Data points with a period of 60 seconds (1 minute) are available for 15 days
Data points with a period of 300 seconds (5 minute) are available for 63 days
Data points with a period of 3600 seconds (1 hour) are available for 455 days (15 months)
The unified CloudWatch agent is a piece of software running on EC2 instances and enables you to do the following: