# CloudWatch

**Day-9: AWS Assignment**

CloudWatch, SNS, AWS CloudTrial, AWS VPC Flowlog

1. What is Cloudwatch? What are the types of monitoring in Cloudwatch? How is pricing different for Detailed Monitoring?
    
    **Amazon CloudWatch** is a monitoring and management service provided by AWS (Amazon Web Services) that offers data and actionable insights to monitor applications, understand and respond to system-wide performance changes, optimize resource utilization, and get a unified view of operational health. It provides you with data and insights to ensure that your applications and infrastructures run smoothly.
    
    **Types of Monitoring in CloudWatch:**
    
    1. **Basic Monitoring**: For Amazon EC2 instances and some other AWS resources, CloudWatch provides metrics at no additional charge. For EC2 instances, these metrics are provided in 5-minute periods.
        
    2. **Detailed Monitoring**: This involves more frequent data collection. For EC2 instances, this translates to metrics in 1-minute periods. This option is not free and incurs additional charges.
        
    3. **Custom Metrics**: Apart from the default metrics provided by AWS for your resources, you can also publish your custom metrics to CloudWatch. This is helpful when you want to monitor specific business operations or the performance of custom software.
        
    
    **Pricing for Detailed Monitoring:**
    
    For Amazon EC2 instances, there's an additional charge when you opt for Detailed Monitoring. With Detailed Monitoring, you get data for your EC2 instances every minute, as opposed to every five minutes with Basic Monitoring. This means more data and quicker insights, but also higher costs.
    
    * Basic Monitoring for EC2: Free, and provides data points every 5 minutes.
        
    * Detailed Monitoring for EC2: Incurs a charge, and provides data points every 1 minute.
        
2. What are the cloudwatch metrics that are available for EC2 instances, EBS Volumes, and Load Balancers?
    
    **For EC2 Instances:**
    
    1. **CPU Utilization**: Measures the percentage of CPU capacity in use by your instance.
        
    2. **Network In/Out**: Tracks the amount of incoming and outgoing network traffic for the instance.
        
    3. **Disk Read/Write Operations**: Monitors the number of read and write operations on instance storage volumes.
        
    4. **Status Check Failures**: Reports the number of failed status checks for the instance.
        
    5. **EBS Volume Metrics**: If your instance is using EBS volumes, you can also monitor metrics related to the EBS volumes attached to it, including volume read/write operations and burst balance.
        
    
    **For EBS Volumes:**
    
    1. **Volume Read/Write Operations**: Measures the number of read and write operations on the EBS volume.
        
    2. **Volume Throughput**: Provides data on the volume's read and write throughput.
        
    3. **Volume Burst Balance**: For General Purpose (SSD) volumes, it shows the percentage of burst balance remaining.
        
    4. **Volume Queue Length**: Tracks the number of read and write operation requests that are waiting to be processed.
        
    5. **Volume Idle Time**: Indicates the percentage of time the volume is idle.
        
    
    **For Load Balancers:**
    
    1. **Request Count**: Measures the total number of requests handled by the load balancer.
        
    2. **Latency**: Tracks the time it takes for a request to be processed by the load balancer.
        
    3. **Unhealthy Host Count**: Reports the number of unhealthy instances behind the load balancer.
        
    4. **HTTP Response Codes**: Provides counts of different HTTP response codes returned by instances.
        
    5. **Active Connections**: This shows the number of active connections to the load balancer.
        
    6. **Processed Bytes**: Measures the number of bytes processed by the load balancer.
        
    7. **Healthy Host Count**: Reports the number of healthy instances behind the load balancer.
        
3. What are Custom metrics in Cloudwatch? Setup Memory Metric for EC2 and push it to Cloudwatch
    

[https://dev.to/drewmullen/send-memory-utilization-metrics-to-cloudwatch-5g28](https://dev.to/drewmullen/send-memory-utilization-metrics-to-cloudwatch-5g28)

**Custom metrics** in Amazon CloudWatch allow you to collect and monitor data specific to your application or use case, beyond the standard AWS metrics.

In custom metrics, the --dimensions parameter is common. A dimension further clarifies what the metric is and what data it stores. You can have up to 30 dimensions assigned to one metric, and each dimension is defined by a name and value pair.

1. What are Cloudwatch Log Groups and Log Insights?
    
    **Amazon CloudWatch Logs** is a service provided by AWS for monitoring, storing, and analyzing log data generated by your applications and AWS resources. CloudWatch Logs can handle log data from a wide variety of sources, including EC2 instances, Lambda functions, containers, and custom applications. Two key concepts within CloudWatch Logs are Log Groups and Log Insights:
    
    1. **Log Groups**:
        
        * **Log Groups** are essentially containers for log streams. They are used to group related log streams together. Log streams are individual sequences of log events generated by a particular source, such as an EC2 instance or a Lambda function.
            
        * You can create log groups to organize your log data in a way that makes sense for your applications and resources. For example, you might create separate log groups for different microservices or different stages of your application's lifecycle.
            
        * Log Groups also have retention settings, which determine how long log data should be stored before it's automatically deleted. You can configure these settings to comply with your organization's retention policies and compliance requirements.
            
    2. **CloudWatch Logs Insights**:
        
        * **CloudWatch Logs Insights** is a powerful feature of CloudWatch Logs that allows you to interactively search and analyze your log data. It provides a query language and a user-friendly interface to explore and gain insights from your log events.
            
        * With CloudWatch Logs Insights, you can quickly identify patterns, troubleshoot issues, and extract valuable information from your logs without the need for complex scripting or external tools.
            
        * You can run ad-hoc queries on your log data or save frequently used queries for future use. The query language is designed to help you filter and aggregate log events based on various criteria, such as time ranges, keywords, and custom fields.
            
        * This tool is particularly useful for real-time monitoring, debugging, and troubleshooting, as it enables you to drill down into log data and find relevant information rapidly.
            
        
        1. What is SNS? Create an SNS topic with your email as a subscriber.
            
    
    **Amazon Simple Notification Service (SNS)** is a fully managed messaging service provided by AWS that enables you to send messages or notifications to a distributed set of recipients, such as subscribers to topics or applications. SNS allows you to decouple the sender of a message from the recipients, making it a flexible and scalable service for sending notifications, alerts, and messages in various scenarios.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695920864042/fa4968b7-68f5-4086-99e5-383660b4898b.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695920996609/77ca70f2-137b-4a31-b402-3aef0b471372.png align="center")
    
    1. 1. Create an EC2 alarm for CPU utilization. Install stress (ref 1) utility, increase CPU and make sure you get an alarm on your email.
            

[https://www.devmanuals.net/install/ubuntu/ubuntu-12-04-lts-precise-pangolin/install-stress.html](https://www.devmanuals.net/install/ubuntu/ubuntu-12-04-lts-precise-pangolin/install-stress.html)

1. Create an Autoscaling Group, and scale-in EC2 instances based on CPU utilisation. Increase CPU utilization on EC2 instances using stress utility.
    
    1. What is AWS CloudTrial? Identify the sequence of events when an EC2 instance is created in CloudTrial.
        
    
    **AWS CloudTrail** is a service provided by Amazon Web Services (AWS) that enables governance, compliance, operational auditing, and risk auditing of your AWS account. It records all actions taken on resources in your AWS account, providing you with a detailed history of events that have occurred.
    
    When an EC2 instance is created in AWS, CloudTrail records a sequence of events that typically includes the following key actions:
    
    1. **User or Role Activity**:
        
        * A user, role, or service assumes a role or uses its permissions to create an EC2 instance.
            
    2. **API Call**:
        
        * The user, role, or service makes an API call to the AWS service (in this case, EC2) to create the instance. The API call might be initiated through the AWS Management Console, AWS CLI, AWS SDK, or any other tool.
            
    3. **CloudTrail Logging**:
        
        * CloudTrail captures the details of the API call, including the action, timestamp, source IP address, and other relevant information.
            
    4. **Log Delivery**:
        
        * The CloudTrail logs are delivered to the specified CloudWatch Logs group and/or an Amazon S3 bucket as configured in your CloudTrail settings.
            
    5. **Processing Logs**:
        
        * CloudWatch Logs or the S3 bucket stores the CloudTrail logs, making them accessible for monitoring and analysis.
            
    6. **Monitoring and Analysis**:
        
        * You can use CloudWatch Logs, CloudWatch Alarms, or third-party log analysis tools to monitor and analyze the CloudTrail logs for specific events, including EC2 instance creation.
            
    7. **Alerts and Actions**:
        
        * You can set up alerts or triggers based on specific events in CloudTrail logs. For example, you can create an alert that notifies you when a new EC2 instance is created.
            
    8. **Compliance and Auditing**:
        
        * CloudTrail logs serve as a record of all AWS activity, helping you meet compliance requirements and providing a historical audit trail for your AWS resources.
            
    9. What are AWS FlowLogs? Enable VPC Flow Logs for an ENI and capture and analyze a VPC Flow log.
        
    
    **AWS VPC Flow Logs** is a feature that allows you to capture information about the IP traffic going to and from network interfaces in your Amazon Virtual Private Cloud (VPC). VPC Flow Logs provide valuable insights into network traffic patterns, which can be useful for security analysis, troubleshooting, and compliance.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695923408482/6b8ec977-00bb-41cc-854f-0256db01746f.png align="left")
