Getting Started / Hands-on / ...
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
- CloudWatch Container Insights - You can use CloudWatch Container Insights to collect, aggregate, and summarize metrics and logs from your containerized applications and Microservices. Container Insights is available for Amazon Elastic Container Service (Amazon ECS), Amazon Elastic Kubernetes Service (Amazon EKS), and Kubernetes platforms on Amazon Elastic Compute Cloud (Amazon EC2). Amazon ECS support includes support for Fargate.
- Amazon CloudWatch Logs - You can use Amazon CloudWatch Logs to monitor, store, and access your log files from Amazon Elastic Container Service (Amazon ECS), Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS CloudTrail, Amazon Route 53, and other sources.
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".
-
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:
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.
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.
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.
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.
-
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.
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.
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.
Application Architecture
With all modules now completed, here is the architecture of what you built:

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.