• /
  • EnglishEspañolFrançais日本語한국어Português
  • EntrarComeçar agora

Esta tradução de máquina é fornecida para sua comodidade.

Caso haja alguma divergência entre a versão em inglês e a traduzida, a versão em inglês prevalece. Acesse esta página para mais informações.

Criar um problema

Monitore o ECS no EC2 com o OpenTelemetry

Monitore as tarefas do Amazon ECS em execução em instâncias de EC2 implantando o OpenTelemetry Collector Contrib como um contêiner sidecar. Este guia abrangente orienta você na criação de definições de tarefa, configuração do coletor e configuração do monitoramento para seus workloads do ECS no EC2.

Etapas de instalação

Siga estas etapas para configurar o monitoramento das suas tarefas do ECS no EC2.

Antes de você começar

Certifique-se de que seu ambiente atenda a estes requisitos:

Armazene sua chave de licença do New Relic

Salve sua chave de licença como um parâmetro do Systems Manager (SSM) para armazenar credenciais com segurança para o OpenTelemetry Collector:

bash
$
aws ssm put-parameter \
>
--name "/newrelic-infra/ecs/license-key" \
>
--type SecureString \
>
--description 'New Relic license key for ECS monitoring' \
>
--value "YOUR_NEW_RELIC_LICENSE_KEY"

Criar política IAM e função de execução

  1. Crie uma política do IAM para que seus contêineres do ECS possam recuperar com segurança a chave de licença da New Relic:

    bash
    $
    aws iam create-policy \
    >
    --policy-name "NewRelicSSMLicenseKeyReadAccess" \
    >
    --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ssm:GetParameters"],"Resource":["arn:aws:ssm:*:*:parameter/newrelic-infra/ecs/license-key"]}]}' \
    >
    --description "Provides read access to the New Relic SSM license key parameter"
  2. Crie uma função do IAM para ser usada como função de execução de tarefas:

    bash
    $
    aws iam create-role \
    >
    --role-name "NewRelicECSTaskExecutionRole" \
    >
    --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ecs-tasks.amazonaws.com"},"Action":"sts:AssumeRole"}]}' \
    >
    --description "ECS task execution role for New Relic infrastructure"
  3. Anexe as políticas gerenciadas necessárias à função:

    bash
    $
    # Attach the standard ECS task execution policy
    $
    aws iam attach-role-policy \
    >
    --role-name "NewRelicECSTaskExecutionRole" \
    >
    --policy-arn "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
    $
    $
    # Attach the New Relic SSM license key read access policy
    $
    aws iam attach-role-policy \
    >
    --role-name "NewRelicECSTaskExecutionRole" \
    >
    --policy-arn "arn:aws:iam::$(aws sts get-caller-identity --query Account --output text):policy/NewRelicSSMLicenseKeyReadAccess"

Armazenar configuração do coletor

Armazene a configuração do OpenTelemetry Collector no AWS Systems Manager Parameter Store para que você possa gerenciar e atualizar as configurações sem reconstruir imagens de contêiner:

bash
$
aws ssm put-parameter \
>
--name "/ecs/otel-collector/ec2-config" \
>
--type "String" \
>
--value "$(cat <<EOF
$
receivers:
$
awsecscontainermetrics:
$
collection_interval: <COLLECTION_INTERVAL>
$
hostmetrics:
$
collection_interval: <COLLECTION_INTERVAL>
$
scrapers:
$
cpu:
$
metrics:
$
system.cpu.time:
$
enabled: false
$
system.cpu.utilization:
$
enabled: true
$
load:
$
memory:
$
metrics:
$
system.memory.utilization:
$
enabled: true
$
paging:
$
metrics:
$
system.paging.utilization:
$
enabled: false
$
system.paging.faults:
$
enabled: false
$
filesystem:
$
metrics:
$
system.filesystem.utilization:
$
enabled: true
$
disk:
$
metrics:
$
system.disk.merged:
$
enabled: false
$
system.disk.pending_operations:
$
enabled: false
$
system.disk.weighted_io_time:
$
enabled: false
$
network:
$
metrics:
$
system.network.connections:
$
enabled: false
$
$
processors:
$
metricstransform/containers:
$
transforms:
$
- include: container.cpu.utilized
$
action: insert
$
new_name: container.cpu.utilization
$
- include: container.memory.usage
$
action: insert
$
new_name: container.memory.usage.total
$
- include: container.storage.read_bytes
$
action: insert
$
new_name: container.blockio.io_service_bytes_recursive
$
operations:
$
- action: add_label
$
new_label: operation
$
new_value: read
$
- include: container.storage.write_bytes
$
action: insert
$
new_name: container.blockio.io_service_bytes_recursive
$
operations:
$
- action: add_label
$
new_label: operation
$
new_value: write
$
metricstransform:
$
transforms:
$
- include: system.cpu.utilization
$
action: update
$
operations:
$
- action: aggregate_labels
$
label_set: [ state ]
$
aggregation_type: mean
$
- include: system.paging.operations
$
action: update
$
operations:
$
- action: aggregate_labels
$
label_set: [ direction ]
$
aggregation_type: sum
$
filter/exclude_cpu_utilization:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.cpu.utilization\" and attributes[\"state\"] == \"interrupt\"'
$
- 'metric.name == \"system.cpu.utilization\" and attributes[\"state\"] == \"nice\"'
$
- 'metric.name == \"system.cpu.utilization\" and attributes[\"state\"] == \"softirq\"'
$
filter/exclude_memory_utilization:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.memory.utilization\" and attributes[\"state\"] == \"slab_unreclaimable\"'
$
- 'metric.name == \"system.memory.utilization\" and attributes[\"state\"] == \"inactive\"'
$
- 'metric.name == \"system.memory.utilization\" and attributes[\"state\"] == \"cached\"'
$
- 'metric.name == \"system.memory.utilization\" and attributes[\"state\"] == \"buffered\"'
$
- 'metric.name == \"system.memory.utilization\" and attributes[\"state\"] == \"slab_reclaimable\"'
$
filter/exclude_memory_usage:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.memory.usage\" and attributes[\"state\"] == \"slab_unreclaimable\"'
$
- 'metric.name == \"system.memory.usage\" and attributes[\"state\"] == \"inactive\"'
$
filter/exclude_filesystem_utilization:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.filesystem.utilization\" and attributes[\"type\"] == \"squashfs\"'
$
filter/exclude_filesystem_usage:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.filesystem.usage\" and attributes[\"type\"] == \"squashfs\"'
$
- 'metric.name == \"system.filesystem.usage\" and attributes[\"state\"] == \"reserved\"'
$
filter/exclude_filesystem_inodes_usage:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.filesystem.inodes.usage\" and attributes[\"type\"] == \"squashfs\"'
$
- 'metric.name == \"system.filesystem.inodes.usage\" and attributes[\"state\"] == \"reserved\"'
$
filter/exclude_system_disk:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.disk.operations\" and IsMatch(attributes[\"device\"], \"^loop.*\") == true'
$
- 'metric.name == \"system.disk.merged\" and IsMatch(attributes[\"device\"], \"^loop.*\") == true'
$
- 'metric.name == \"system.disk.io\" and IsMatch(attributes[\"device\"], \"^loop.*\") == true'
$
- 'metric.name == \"system.disk.io_time\" and IsMatch(attributes[\"device\"], \"^loop.*\") == true'
$
- 'metric.name == \"system.disk.operation_time\" and IsMatch(attributes[\"device\"], \"^loop.*\") == true'
$
filter/exclude_system_paging:
$
metrics:
$
datapoint:
$
- 'metric.name == \"system.paging.usage\" and attributes[\"state\"] == \"cached\"'
$
- 'metric.name == \"system.paging.operations\" and attributes[\"type\"] == \"cached\"'
$
filter/exclude_network:
$
metrics:
$
datapoint:
$
- 'IsMatch(metric.name, \"^system.network.*\") == true and attributes[\"device\"] == \"lo\"'
$
$
attributes/exclude_system_paging:
$
include:
$
match_type: strict
$
metric_names:
$
- system.paging.operations
$
actions:
$
- key: type
$
action: delete
$
$
cumulativetodelta:
$
$
transform/host:
$
metric_statements:
$
- context: metric
$
statements:
$
- set(metric.description, \"\")
$
- set(metric.unit, \"\")
$
$
transform:
$
trace_statements:
$
- context: span
$
statements:
$
- truncate_all(span.attributes, <ATTRIBUTE_TRUNCATION_LIMIT>)
$
- truncate_all(resource.attributes, <RESOURCE_ATTRIBUTE_TRUNCATION_LIMIT>)
$
log_statements:
$
- context: log
$
statements:
$
- truncate_all(log.attributes, <ATTRIBUTE_TRUNCATION_LIMIT>)
$
- truncate_all(resource.attributes, <RESOURCE_ATTRIBUTE_TRUNCATION_LIMIT>)
$
$
memory_limiter:
$
check_interval: <MEMORY_LIMITER_CHECK_INTERVAL>
$
limit_mib: \${env:NEW_RELIC_MEMORY_LIMIT_MIB:-<MEMORY_LIMIT_MIB>}
$
batch:
$
send_batch_size: <SEND_BATCH_SIZE>
$
timeout: <BATCH_TIMEOUT>
$
resource:
$
attributes:
$
- key: ClusterName
$
from_attribute: aws.ecs.cluster.name
$
action: insert
$
- key: ServiceName
$
from_attribute: aws.ecs.service.name
$
action: insert
$
- key: TaskId
$
from_attribute: aws.ecs.task.id
$
action: insert
$
- key: TaskDefinitionFamily
$
from_attribute: aws.ecs.task.family
$
action: insert
$
- key: LaunchType
$
from_attribute: aws.ecs.launch_type
$
action: insert
$
$
resourcedetection:
$
detectors:
$
- env
$
- ecs
$
- ec2
$
- system
$
timeout: <RESOURCE_DETECTION_TIMEOUT>
$
override: false
$
$
exporters:
$
otlphttp:
$
endpoint: https://otlp.nr-data.net:443
$
headers:
$
api-key: \${NEW_RELIC_LICENSE_KEY}
$
$
debug:
$
verbosity: basic
$
$
service:
$
pipelines:
$
metrics/containers:
$
receivers: [awsecscontainermetrics]
$
processors: [metricstransform/containers, resource, batch]
$
exporters: [otlphttp, debug]
$
metrics/host:
$
receivers: [hostmetrics]
$
processors:
$
- memory_limiter
$
- metricstransform
$
- filter/exclude_cpu_utilization
$
- filter/exclude_memory_utilization
$
- filter/exclude_memory_usage
$
- filter/exclude_filesystem_utilization
$
- filter/exclude_filesystem_usage
$
- filter/exclude_filesystem_inodes_usage
$
- filter/exclude_system_disk
$
- filter/exclude_network
$
- attributes/exclude_system_paging
$
- transform/host
$
- resourcedetection
$
- cumulativetodelta
$
- batch
$
exporters: [otlphttp, debug]
$
EOF
$
)"

Parâmetro de configuração

Os seguintes parâmetros podem ser personalizados na configuração do OpenTelemetry Collector:

Parâmetro

Descrição

<COLLECTION_INTERVAL>

Intervalo para coletar métricas dos endpoints de métricas do contêiner ECS e do host.

<MEMORY_LIMIT_MIB>

Limite de memória para o OpenTelemetry Collector em MiB

<MEMORY_LIMITER_CHECK_INTERVAL>

Intervalo para o limitador de memória verificar o uso atual de memória

<SEND_BATCH_SIZE>

Número de métricas a serem agrupadas em lote antes de enviar para o New Relic

<BATCH_TIMEOUT>

Tempo máximo de espera antes de enviar um lote

<RESOURCE_DETECTION_TIMEOUT>

Tempo limite para processadores de detecção de recursos

<ATTRIBUTE_TRUNCATION_LIMIT>

Comprimento máximo para valores de atributos de span e log antes do truncamento. Padrão: 4.095

<RESOURCE_ATTRIBUTE_TRUNCATION_LIMIT>

Comprimento máximo para valores de atributos de recurso antes do truncamento. Padrão: 4.095

Criar definição de tarefa

Crie uma nova definição de tarefa do ECS que inclua o contêiner sidecar do OpenTelemetry Collector. Escolha a definição de tarefa apropriada para sua plataforma de contêiner:

Parâmetros de definição de tarefa

Os seguintes parâmetros podem ser personalizados na sua definição de tarefa do ECS:

Parâmetro

Descrição

<TASK_CPU>

Total de unidades de CPU para a tarefa EC2

<TASK_MEMORY>

Memória total para a tarefa do EC2 em MiB

<APP_CPU>

Unidades de CPU alocadas ao seu contêiner de aplicativo

<APP_MEMORY>

Memória alocada ao seu contêiner de aplicativo em MiB

<COLLECTOR_CPU>

Unidades de CPU alocadas ao OpenTelemetry Collector

<COLLECTOR_MEMORY>

Memória alocada para o OpenTelemetry Collector em MiB

<APP_LOG_GROUP>

Nome do grupo de logs do CloudWatch para o contêiner do seu aplicativo

<COLLECTOR_LOG_GROUP>

Nome do grupo de logs do CloudWatch para o OpenTelemetry Collector

<AWS_REGION>

Região da AWS para logs do CloudWatch

<APP_LOG_STREAM_PREFIX>

Prefixo do stream de log para o contêiner do seu aplicativo

<COLLECTOR_LOG_STREAM_PREFIX>

Prefixo do fluxo de log para o OpenTelemetry Collector

Dica

O networkMode está definido como "host" para contêineres Linux e deve ser "default" para contêineres Windows. O modo host oferece melhor acesso às métricas do sistema em instâncias de EC2.

Importante

Substitua os valores de YOUR_ACCOUNT e da região pelo ID da sua conta da AWS e região da AWS reais.

Implantar e executar a tarefa

Implante sua definição de tarefa em seu cluster ECS:

  1. Registre a definição de tarefa:

    bash
    $
    aws ecs register-task-definition --cli-input-json file://task-definition.json
  2. Criar um serviço com estratégia de agendamento daemon:

    bash
    $
    aws ecs create-service \
    >
    --cluster your-cluster-name \
    >
    --service-name otel-monitoring-service \
    >
    --task-definition otel-ecs-ec2-sidecar-metrics:1 \
    >
    --scheduling-strategy DAEMON \
    >
    --launch-type EC2

    Dica

    A estratégia de agendamento DAEMON garante que uma tarefa de monitoramento seja executada em cada instância de EC2 do seu cluster, fornecendo cobertura abrangente de monitoramento de infraestrutura.

Verificar coleta de dados

Verifique se seus dados estão fluindo para o New Relic:

Próximos passos

Após configurar o monitoramento, você pode:

Copyright © 2026 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.