Post

AWS Monitoring

πŸ” Exploring the Power of AWS Monitoring

Discover the capabilities and benefits of AWS CloudWatch for comprehensive monitoring and observability of your AWS infrastructure and applications.

AWS CloudWatch 🌟

Metrics πŸ“Š

  • Collect and track key metrics.
  • Provides metrics for every service in AWS like CPUUtilization etc.
  • Metrics belongs to Namespaces (The below boxes are the different built-in namespaces) alt text alt text
  • Dimensions is an attribute of a metric (Upto 30), This means that for any given metric, you can include up to 30 different attributes or categorizations to further segment and analyze the data. Let’s check the CPUUtilization metric with the dimension as the instanceId under the namespace EC2. alt text alt text
  • Create dashboards using metrics. alt text alt text alt text alt text

Custom Metrics πŸ“ˆ

  • Define own custom metrics.
  • Using the API call PutMetricData with the usage of dimensions and metrics resolution (StorageResolution: Standard and high Resolution)
  • Below is the custom metric that we will push using cloudshell
1
aws cloudwatch put-metric-data --metric-name Buffers --namespace MyNameSpace --unit Bytes --value 231434333 --dimensions InstanceId=1-23456789,InstanceType=m1.small
  • We will see the new namespace and the custom metric under it. alt text alt text

Logs πŸ“œ

  • Collect monitor and analyze logs.
  • Log groups: name representing the application alt text alt text
  • Log stream: instances within application, logs or containers. alt text alt text
  • Can apply metric filter based on the log stream alt text alt text
  • Create a metric filter and save (If the value will be found in our case SUCCEDDED the corresponding data point on the metric will be 1) alt text alt text
  • Using this we can create the alarms as well.
  • Logs can be send to S3 as export.
  • Logs insight can be used as a query.

Alarms ⏰

  • React to these metrics.
  • Three states:
    • OK (Not triggered)
    • INSUFFICIENT_DATA (Not enough data)
    • ALARM (A threashold has reached and notification will be sent)
  • Three main targets:
    • EC2
    • EC2 Auto scaling
    • SNS (and then lambda so that we can do anything)
  • Composite alarms are monitoring the state of multiple other alarms.

Let’s create an alarm on EC2 instance which will terminate the EC2 instance which is running on high CPU for 15 minutes (Instead of waiting for 15 minutes I will use api call to put the alarm in ALARM state)

  • Create an EC2 instance, create a metric alarm using the perinstance metric and choosing CPUUtilization. alt text alt text alt text alt text alt text alt text
  • Check the newly created alarm alt text alt text
  • Using cloud shell to trigger the alarm
    1
    
    aws cloudwatch set-alarm-state --alarm-name "EC2-Trigger-Alarm" --state-value ALARM --state-reason "testing purposes"
    
  • Check the alarm status alt text alt text
  • Check the status now of the EC2 instance alt text alt text

AWS EventBridge πŸŽ‰

  • Events from the AWS services can be used to trigger other services, like if EC2 instance stops or terminated then we want to send an SNS notification.
  • This can be a schedule cronjob as well to trigger the target service.
  • Let’s us now create the event bridge to send an email when any EC2 gets stopped or terminated. alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text
This post is licensed under CC BY 4.0 by the author.