Getting Started with AWS

Deploy a .NET Web Application on Amazon ECS powered by Graviton2

Module 6: Monitoring and Logging

In this module, you will set up monitoring for your ECS environment using Amazon CloudWatch Container Insights

Overview

This final module will focus on how you can set up monitoring for your ECS environment using Amazon CloudWatch Container Insights. This can be used to collect, aggregate, and summarize metrics and logs from your containerised application. Container Insights also provides diagnostic information, such as container restart failures, to help you isolate issues and resolve them quickly. You can also set CloudWatch alarms on metrics that Container Insights collects.

What You Will Learn

In this module, you will learn how to monitor the metrics and logs from your application running in ECS. As part of the deployment, you created an ECS Cluster, Service and Task. In addition to this, the .NET application is configure to provide logs to STDOUT. You will learn the following from this module:

  • Visualizing metrics and gaining insights at the ECS Cluster, Server and Task level
  • Visualizing application logs in CloudWatch.

Key Concepts

 Time to Complete

15 minutes

 Services Used

Implementation

  • Confirm Container Insights is Enabled

    1. If for any reason, you missed enabling Container Insights in Module 4, you can enable it via AWS CLI on existing Amazon ECS clusters using the command below:

    aws ecs update-cluster-settings --cluster Graviton2ECSCluster --settings name=containerInsights,value=enabled --region ${AWS_REGION}

    2. From the response of the command, confirm that the settings has a setting with name "containerInsights" and value "enabled".

    ECS check ContainerInsights is enabled
  • Visualizing Container Insights in CloudWatch

    1. Navigate to the Amazon CloudWatch Console by typing “CloudWatch” in the search box, and selecting the service name as shown below:

    Navigate to CloudWatch

    2. The CloudWatch console is displayed as below. Ensure the “New menu experience” is selected in the top left corner of the screen, to be able to use the new CloudWatch console. On the menu on the left, click on “Container Insights” under the “Insights” section.

    CloudWatch overview

    3. The Container Insights dashboard is displayed as below. Ensure the “List View” is selected in the top right corner to show the list of the container resources. You can see the “Graviton2ECSCluster”, “Graviton2ECSService”, and “Graviton2ECSTask” which are the resources created so far.

    CloudWatch Container Insights resources

    4. Container Insights provides metrics for each of these resources to help provide visibility on what is going on within the resources. Click on each of the resources to see the metrics as show below.

    Cluster metrics - this provides a view of the CPU Utilization, Memory Utilization and Network Transferred and Received. It also provides a view of the count of Container Instance, Task and Service within the cluster.

    CloudWatch Container Insights cluster metrics

    Service metrics - provides a view of the aggregated metrics of the tasks running within the service and also the performance for each of the tasks.

    Task metrics - provides a view of the metrics for each task running in the cluster.

    CloudWatch Container Insights task metrics
  • Analyzing Application Logs via CloudWatch

    While creating the Task Definition as shown in Module 4, you enabled Log Configuration and specified a name for the log group. This will enable the application logs that were previously sent out to standard output to be sent to Amazon CloudWatch Logs. In this step, you will see how to review the application logs sent to CloudWatch.

    1. Navigate to the CloudWatch Console and click on Log Group under Logs in the left menu.

    CloudWatch Log groups

    2. The Log Group that was configured in Module 4 while creating the task definition is “/ecs/Graviton2ECSTask“. Select this log group to show the log streams from the containers in the ECS task. Sending logs to Cloudwatch logs enables you to view different logs from your containers in one convenient location, and it prevents your container logs from taking up disk space on your container instances. 

    CloudWatch Log groups ECS Task

    3. Select a log stream to display the application logs. In the top right corner of the screen you can specify filters based on date and time to retrieve the logs.

    CloudWatch Log groups ECS Task Log events

Application Architecture

With all modules now completed, here is the architecture of what you built:

Architecture module 6

Conclusion

If you intend to implement tracing, you can use AWS X-Ray which is a service that collects data about requests that your application serves, and provides tools you can use to view, filter and gain insights into that data to identify issues and opportunities for optimisation. You can run AWS X-Ray daemon on Amazon ECS to trace requests to your application. This can be set up following the guide here.

Was this module helpful?

Thank you
Please let us know what you liked.
Close
Sorry to disappoint you
Is something out-of-date, confusing or inaccurate? Please help us improve this tutorial by providing feedback.
Close