

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon Managed Service for Prometheus에서 OpenSearch Ingestion 파이프라인 사용
<a name="configure-client-prometheus"></a>

Amazon Managed Service for Prometheus를 OpenSearch Ingestion 파이프라인의 대상으로 사용하여 지표를 시계열 형식으로 저장할 수 있습니다. Prometheus 싱크를 사용하면 파이프라인의 OpenTelemetry 지표 또는 기타 시계열 데이터를 모니터링, 알림 및 분석을 위해 Amazon Managed Service for Prometheus 워크스페이스로 전송할 수 있습니다.

`prometheus` 싱크 플러그인을 사용하면 OpenSearch Ingestion 파이프라인이 Prometheus 원격 쓰기 프로토콜을 사용하여 Amazon Managed Service for Prometheus 워크스페이스에 지표 데이터를 쓸 수 있습니다. 이 통합을 통해 다음을 수행할 수 있습니다.
+ Amazon Managed Service for Prometheus에 시계열 지표 데이터 저장
+ Amazon Managed Service for Prometheus 및 Amazon Managed Grafana를 사용하여 지표 모니터링 및 알림
+ 지표를 여러 대상으로 동시에 라우팅(예: OpenSearch 및 Amazon Managed Service for Prometheus)
+ 외부 에이전트의 OpenTelemetry 지표를 처리하거나 파이프라인 내에서 지표를 생성합니다.

**Topics**
+ [사전 조건](#prometheus-prereqs)
+ [1단계: 파이프라인 역할 구성](#prometheus-pipeline-role)
+ [2단계: 파이프라인 생성](#prometheus-pipeline)
+ [모니터링 및 문제 해결](#prometheus-monitoring)
+ [제한 사항](#prometheus-limitations)
+ [모범 사례](#prometheus-best-practices)

## 사전 조건
<a name="prometheus-prereqs"></a>

Prometheus 싱크를 구성하기 전에 다음이 있는지 확인합니다.
+ **Amazon Managed Service for Prometheus 워크**스페이스: OpenSearch Ingestion 파이프라인 AWS 리전 과 동일한 AWS 계정 및에 워크스페이스를 생성합니다. 지침은 *Amazon Managed Service for Prometheus 사용 설명서*의 [워크스페이스 생성을](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html) 참조하세요.
+ **IAM 권한**: Amazon Managed Service for Prometheus에 쓸 수 있는 권한이 있는 IAM 역할을 구성합니다. 자세한 내용은 [1단계: 파이프라인 역할 구성](#prometheus-pipeline-role) 단원을 참조하십시오.

## 1단계: 파이프라인 역할 구성
<a name="prometheus-pipeline-role"></a>

Prometheus 싱크는 인증에 대한 [파이프라인 역할의](pipeline-security-overview.md#pipeline-security-sink) IAM 권한을 자동으로 상속하므로 싱크 설정에서 추가 역할 구성(예: `sts_role_arn`)이 필요하지 않습니다.

다음 샘플 정책은 Amazon Managed Service for Prometheus를 싱크로 사용하는 데 필요한 권한을 보여줍니다.

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AMPRemoteWrite",
      "Effect": "Allow",
      "Action": [
        "aps:RemoteWrite"
      ],
      "Resource": "arn:aws:aps:{{region}}:{{account-id}}:workspace/{{workspace-id}}"
    }
  ]
}
```

다음과 같이 자리 표시자를 바꿉니다.
+ `{{region}}`: AWS 리전 (예: `us-east-1`)
+ `{{account-id}}`: ID AWS 계정 
+ `{{workspace-id}}`: Amazon Managed Service for Prometheus 워크스페이스 ID

파이프라인 역할에 이러한 권한을 연결해야 합니다.

파이프라인 역할에 OpenSearch Ingestion이 이를 수임할 수 있는 신뢰 관계가 있는지 확인합니다.

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "osis-pipelines.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

## 2단계: 파이프라인 생성
<a name="prometheus-pipeline"></a>

권한을 설정한 후 Amazon Managed Service for Prometheus를 싱크로 사용하도록 OpenSearch Ingestion 파이프라인을 구성할 수 있습니다.

### 기본 구성
<a name="prometheus-basic-config"></a>

다음 예제에서는 최소 Prometheus 싱크 구성을 보여줍니다.

```
version: "2"
sink:
  - prometheus:
      url: "https://aps-workspaces.{{region}}.amazonaws.com/workspaces/{{workspace-id}}/api/v1/remote_write"
      aws:
        region: "{{region}}"
```

`prometheus` 싱크 구성 내에서 Amazon Managed Service for Prometheus 원격 쓰기 엔드포인트인 `url` 옵션을 지정해야 합니다. URL의 형식을 지정하려면 Amazon Managed Service for Prometheus 콘솔에서 워크스페이스 ID를 찾고 URL을 다음과 같이 구성합니다`https://aps-workspaces.{{region}}.amazonaws.com/workspaces/{{workspace-id}}/api/v1/remote_write`.

### 구성 옵션
<a name="prometheus-config-options"></a>

다음 옵션을 사용하여 Prometheus 싱크에 대한 일괄 처리 및 플러시 동작을 구성합니다.


**Prometheus 싱크 구성 옵션**  

| 옵션 | 필수 | 유형 | 설명 | 
| --- | --- | --- | --- | 
| max\_events | 아니요 | Integer | Prometheus로 플러시하기 전에 누적할 최대 이벤트 수입니다. 기본값은 1000입니다. | 
| max\_request\_size | 아니요 | 바이트 수 | 플러시 전 요청 페이로드의 최대 크기입니다. 기본값은 1mb입니다. | 
| flush\_interval | 아니요 | 지속 시간 | 이벤트를 플러시하기 전에 대기하는 최대 시간입니다. 기본값은 10s입니다. 허용되는 최대 값은 입니다60s. | 

### 파이프라인 예제
<a name="prometheus-example-pipelines"></a>

**예제 1: Amazon Managed Service for Prometheus에 대한 OpenTelemetry 지표**

이 파이프라인은 외부 에이전트로부터 OpenTelemetry 지표를 수신하여 Amazon Managed Service for Prometheus에 기록합니다.

```
version: "2"
source:
  otel_metrics_source:
    path: "/v1/metrics"
    output_format: otel

sink:
  - prometheus:
      url: "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111/api/v1/remote_write"
      aws:
        region: "us-east-1"
```

**예제 2: 듀얼 싱크 - OpenSearch 및 Amazon Managed Service for Prometheus**

이 파이프라인은 OpenSearch와 Amazon Managed Service for Prometheus 모두에 지표를 라우팅합니다.

```
version: "2"
source:
  otel_metrics_source:
    path: "/v1/metrics"
    output_format: otel

sink:
  - opensearch:
      hosts:
        - "https://search-{{domain-endpoint}}.{{us-east-1}}.es.amazonaws.com"
      index: "metrics-%{yyyy.MM.dd}"
      aws:
        region: "us-east-1"
        sts_role_arn: "arn:aws:iam::123456789012:role/OSI-Pipeline-Role"

  - prometheus:
      url: "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111/api/v1/remote_write"
      aws:
        region: "us-east-1"
```

**예제 3: 필터링이 포함된 지표**

이 파이프라인은 Amazon Managed Service for Prometheus로 전송하기 전에 지표를 필터링합니다.

```
version: "2"
source:
  otel_metrics_source:
    path: "/v1/metrics"
    output_format: otel

processor:
  - drop_events:
      drop_when: '/name != "http.server.duration" and /name != "http.client.duration"'

sink:
  - prometheus:
      url: "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111/api/v1/remote_write"
      aws:
        region: "us-east-1"
```

사전 구성된 Amazon Managed Service for Prometheus 블루프린트를 사용하여 이러한 파이프라인을 생성할 수 있습니다. 자세한 내용은 [블루프린트 작업](pipeline-blueprint.md) 단원을 참조하십시오.

### Amazon Managed Service for Prometheus 싱크를 사용하여 파이프라인 생성
<a name="prometheus-create-pipeline"></a>

#### AWS 콘솔 사용
<a name="prometheus-console"></a>

1. OpenSearch Service 콘솔로 이동합니다.

1. **수집**에서 **파이프라인**을 선택합니다.

1. [**파이프라인 생성**]을 선택합니다.

1. **블루프린트를 사용하여 빌드**를 선택하고 **Amazon Prometheus 블루프린트에 대한 OpenTelemetry 지표**를 선택합니다.

1. 파이프라인을 구성합니다.
   + Amazon Managed Service for Prometheus 워크스페이스 ID 입력
   + 파이프라인 역할 ARN 지정
   + 필요에 따라 소스 및 프로세서 설정 구성

1. 파이프라인을 검토하고 생성합니다.

#### AWS CLI 사용
<a name="prometheus-cli"></a>

원하는 구성으로 파이프라인 구성 파일(예: `amp-pipeline.yaml`)을 생성한 다음 다음을 실행합니다.

```
aws osis create-pipeline \
  --pipeline-name my-amp-pipeline \
  --min-units 2 \
  --max-units 4 \
  --pipeline-configuration-body file://amp-pipeline.yaml
```

#### 사용 AWS CloudFormation
<a name="prometheus-cfn"></a>

```
Resources:
  MyAMPPipeline:
    Type: AWS::OSIS::Pipeline
    Properties:
      PipelineName: my-amp-pipeline
      MinUnits: 2
      MaxUnits: 4
      PipelineConfigurationBody: |
        version: "2"
        source:
          otel_metrics_source:
            path: "/v1/metrics"
            output_format: otel
        sink:
          - prometheus:
              url: "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111/api/v1/remote_write"
              aws:
                region: "us-east-1"
```

## 모니터링 및 문제 해결
<a name="prometheus-monitoring"></a>

### CloudWatch 지표
<a name="prometheus-cloudwatch-metrics"></a>

CloudWatch 지표를 사용하여 파이프라인의 성능을 모니터링합니다.
+ `DocumentsWritten`: Amazon Managed Service for Prometheus에 성공적으로 기록된 지표 수
+ `DocumentsWriteFailed`: 쓰기에 실패한 지표 수
+ `RequestLatency`: 원격 쓰기 요청의 지연 시간

### 일반적인 문제
<a name="prometheus-troubleshooting"></a>

**문제**: 파이프라인이 Amazon Managed Service for Prometheus에 쓰지 못함

**솔루션:**
+ URL의 워크스페이스 ID 및 리전이 올바른지 확인
+ 파이프라인 역할에 `aps:RemoteWrite` 권한이 있는지 확인합니다.
+ 워크스페이스가 서비스 관리형 AWS KMS 키를 사용하는지 확인
+ 파이프라인과 워크스페이스가 동일한지 확인 AWS 계정

**문제**: 인증 오류

**솔루션:**
+ 신뢰 관계가가 파이프라인 역할을 수임`osis-pipelines.amazonaws.com`하도록 허용하는지 확인
+ 파이프라인 역할에 필요한 `aps:RemoteWrite` 권한이 있는지 확인합니다.

**문제**: 높은 지연 시간 또는 제한

**솔루션:**
+ 파이프라인 용량 단위 증가
+ 프로세서에서 일괄 처리 구현
+ Amazon Managed Service for Prometheus 서비스 할당량 검토

## 제한 사항
<a name="prometheus-limitations"></a>

Amazon Managed Service for Prometheus용 OpenSearch Ingestion 파이프라인을 설정할 때 다음 제한 사항을 고려하세요.
+ Amazon Managed Service for Prometheus 워크스페이스는 서비스 관리형 AWS KMS 키를 사용해야 AWS 합니다. 고객 관리형 AWS KMS 키는 현재 지원되지 않습니다.
+ 파이프라인과 Amazon Managed Service for Prometheus 워크스페이스는 동일한에 있어야 합니다 AWS 계정.

## 모범 사례
<a name="prometheus-best-practices"></a>
+ **동일한 IAM 역할 사용**: Prometheus 싱크는 파이프라인 역할을 자동으로 사용합니다. 다른 싱크를 사용하는 경우 `sts_role_arn`가 파이프라인 역할과 동일한지 확인합니다.
+ **지표 모니터링**: 실패한 쓰기 및 긴 지연 시간에 대한 CloudWatch 경보 설정
+ **필터링 구현**: Amazon Managed Service for Prometheus로 전송하기 전에 프로세서를 사용하여 불필요한 지표 필터링
+ **적절한 크기 용량**: 최소 용량으로 시작하고 지표 볼륨에 따라 확장
+ **블루프린트 사용**: 일반적인 사용 사례에 대해 사전 구성된 블루프린트 활용