

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon OpenSearch Service のマネージド Prometheus コレクターを設定する
<a name="prom-opensearch-integration"></a>

Amazon OpenSearch Service 用 Amazon Managed Service for Prometheus マネージドコレクターは、OpenSearch Service ドメインから Prometheus 互換メトリクスを自動的にスクレイプし、送信先に転送します。Amazon Managed Service for Prometheus はコレクターを管理し、インスタンス、エージェント、スクレイパーを自分で管理することなく、必要なスケーラビリティ、セキュリティ、信頼性を提供します。送信先は、Amazon Managed Service for Prometheus ワークスペースまたは Amazon CloudWatch です。

Amazon Elastic Kubernetes Service または Amazon Managed Streaming for Apache Kafka と統合するスクレイパーを作成することもできます。詳細については、[「Amazon EKS の統合](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-collector-how-to.html)」および[「Amazon MSK の統合](https://docs.aws.amazon.com/prometheus/latest/userguide/prom-msk-integration.html)」を参照してください。

## スクレイパーの作成
<a name="prom-opensearch-create-scraper"></a>

この手順では、Amazon OpenSearch Service ドメイン管理と Amazon Virtual Private Cloud ネットワーキングの概念に精通していることを前提としています。

OpenSearch Service ドメインのスクレイパーを作成するには、いくつかの前提条件があります。
+ Amazon Virtual Private Cloud アクセスを持つ Amazon OpenSearch Service ドメイン。マネージドコレクターは、VPC アクセスを持つ OpenSearch Service ドメインのみをサポートします。パブリックアクセスを備えたドメインはサポートされていません。
+ マネージドコレクターが HTTPS (ポート 443) 経由で OpenSearch Service ドメインエンドポイントに到達できるようにするセキュリティグループ。ドメインのセキュリティグループに、コレクター用に指定したセキュリティグループからの HTTPS トラフィックを許可するインバウンドルールを追加します。

収集する OpenSearch Service ドメインをスクレイパーに指示するには、リクエストの `exporters`フィールドにドメインを指定します。`exporters` フィールドはエクスポーター設定のリストを取得します。OpenSearch Service ドメインの場合は、ドメイン`domainArn`の `openSearchConfiguration`を に提供します。次の例に示すように、 `source`フィールドにネットワーク (サブネットとセキュリティグループ) を個別に指定します。

**注記**  
スクレイパーは、スクレイパーの作成時に解決されたドメインの VPC エンドポイントを使用します。ドメインを再作成する場合、新しいエンドポイントを取得するため、新しいスクレイパーを作成するか、[UpdateScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_UpdateScraper.html) で既存のスクレイパーを更新してドメインから収集する必要があります。

スクレイパーの作成時にスクレイプ設定を指定します。マネージドコレクターは指定したドメインに接続してメトリクスを自動的に収集するので、設定内でスクレープターゲットを指定する必要はありません。設定には、`scrape_configs` が正確に `job_name` であるジョブがある `opensearch-exporter` セクションを含める必要があります。という名前のジョブを含まない設定`opensearch-exporter`は拒否されます。スクレイプ設定を使用してスクレイプ間隔を設定し、オプションで収集したメトリクスをフィルタリングまたは再ラベル付けします。スクレイプ設定の例を次に示します。

```
global:
  external_labels:
    domain_name: {{my-opensearch-domain}}

scrape_configs:
  - job_name: opensearch-exporter
    scrape_interval: 60s
```

サポートされているスクレイプ設定オプションの詳細については、「」を参照してください[スクレイパー設定](AMP-collector-how-to.md#AMP-collector-configuration)。

------
#### [ To create a scraper using the AWS API ]

`CreateScraper` API オペレーションを使用して、 AWS API でスクレイパーを作成します。次の例では、OpenSearch Service ドメインからメトリクスを収集し、Amazon Managed Service for Prometheus ワークスペースに送信するスクレイパーを米国東部 (バージニア北部) リージョンに作成します。{{サンプル}}コンテンツを独自のドメイン、ネットワーク、ワークスペース情報に置き換え、スクレイパー設定を指定します。

**注記**  
OpenSearch Service ドメインの Amazon VPC と一致するようにセキュリティグループとサブネットを設定します。2 つのアベイラビリティーゾーンに少なくとも 2 つのサブネットを含めます。

```
POST /scrapers HTTP/1.1

{
    "alias": "{{myScraper}}",
    "source": {
        "vpcConfiguration": {
            "securityGroupIds": ["{{sg-security-group-id}}"],
            "subnetIds": ["{{subnet-subnet-id-1}}", "{{subnet-subnet-id-2}}"]
        }
    },
    "exporters": [
        {
            "openSearchConfiguration": {
                "domainArn": "arn:aws:es:{{us-east-1}}:{{123456789012}}:domain/{{my-opensearch-domain}}"
            }
        }
    ],
    "destination": {
        "ampConfiguration": {
            "workspaceArn": "arn:aws:aps:{{us-east-1}}:{{123456789012}}:workspace/{{ws-workspace-id}}"
        }
    },
    "scrapeConfiguration": {
        "configurationBlob": "{{base64-encoded-blob}}"
    }
}
```

Amazon Managed Service for Prometheus ワークスペースの代わりにメトリクスを Amazon CloudWatch に送信するには、 `destination`を CloudWatch 設定に置き換えます。

```
    "destination": {
        "cloudWatchConfiguration": {
            "datasetArn": "arn:aws:cloudwatch:{{us-east-1}}:{{123456789012}}:dataset/default"
        }
    }
```

`scrapeConfiguration` パラメータには、base64 でエンコードされた Prometheus 設定 YAML ファイルが必要です。次のいずれかのコマンドを実行して、YAML ファイルを base64 に変換します。任意のオンライン base64 コンバーターを使用してファイルを変換することもできます。

**Example Linux/macOS**  

```
base64 -w0 {{scraper-config.yaml}}
```

**Example Windows PowerShell**  

```
[Convert]::ToBase64String([System.IO.File]::ReadAllBytes("{{scraper-config.yaml}}"))
```

------
#### [ To create a scraper using the AWS CLI ]

`create-scraper` コマンドを使用して AWS Command Line Interfaceでスクレイパーを作成します。次の例のコマンドは、米国東部 (バージニア北部) リージョンにスクレイパーを作成します。{{サンプル}}コンテンツを独自のドメイン、ネットワーク、ワークスペース情報に置き換え、スクレイパー設定を指定します。

**注記**  
OpenSearch Service ドメインの Amazon VPC と一致するようにセキュリティグループとサブネットを設定します。2 つのアベイラビリティーゾーンに少なくとも 2 つのサブネットを含めます。

```
aws amp create-scraper \
 --source '{"vpcConfiguration":{"securityGroupIds":["{{sg-security-group-id}}"],"subnetIds":["{{subnet-subnet-id-1}}","{{subnet-subnet-id-2}}"]}}' \
 --exporters '[{"openSearchConfiguration":{"domainArn":"arn:aws:es:{{us-east-1}}:{{123456789012}}:domain/{{my-opensearch-domain}}"}}]' \
 --scrape-configuration configurationBlob={{base64-encoded-blob}} \
 --destination '{"ampConfiguration":{"workspaceArn":"arn:aws:aps:{{us-east-1}}:{{123456789012}}:workspace/{{ws-workspace-id}}"}}'
```

------
+  AWS API で使用できるスクレイパーオペレーションの完全なリストを次に示します。

  [CreateScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_CreateScraper.html) API オペレーションを使用してスクレイパーを作成します。
+ [ListScrapers](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_ListScrapers.html) API オペレーションを使用して既存のスクレイパーを一覧表示します。
+ [UpdateScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_UpdateScraper.html) API オペレーションを使用して、スクレイパーのエイリアス、設定、または送信先を更新します。
+ [DeleteScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DeleteScraper.html) API オペレーションを使用してスクレイパーを削除します。
+ [DescribeScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DescribeScraper.html) API オペレーションを使用してスクレイパーの詳細を取得します。

## クロスアカウントの設定
<a name="prom-opensearch-cross-account"></a>

クロスアカウント設定でスクレイパーを作成するには、メトリクスを収集する OpenSearch Service ドメインが Amazon Managed Service for Prometheus コレクターとは異なるアカウントにある場合、次の手順を使用します。

たとえば、OpenSearch Service ドメイン`account_id_source`があるソースアカウントと、Amazon Managed Service for Prometheus ワークスペース`account_id_target`があるターゲットアカウントの 2 つのアカウントがあるとします。

**注記**  
次の手順の信頼ポリシーは、ARN によるスクレイパーを参照します。これには、スクレイパーを作成するまで存在しない {{scraper-id}} が含まれます。この順序付けの問題を回避するには、まず特定のスクレイパー ARN の代わりにワイルドカード (`scraper/*`) を使用してロールを作成し、スクレイパーを作成し、両方の信頼ポリシーを更新して、ワイルドカードを が`CreateScraper`返す実際のスクレイパー ARN に置き換えます。

**クロスアカウント設定でスクレイパーを作成するには**

1. ソースアカウントで、ロール `arn:aws:iam::{{111122223333}}:role/Source` を作成し、次の信頼ポリシーを追加します。

   ```
   {
       "Effect": "Allow",
       "Principal": {
       "Service": [
           "scraper.aps.amazonaws.com"
        ]
       },
       "Action": "sts:AssumeRole",
       "Condition": {
           "ArnEquals": {
               "aws:SourceArn": "arn:aws:aps:{{aws-region}}:{{111122223333}}:scraper/{{scraper-id}}"
           },
           "StringEquals": {
               "AWS:SourceAccount": "{{111122223333}}"
           }
       }
   }
   ```

1. ターゲットアカウントで、ロールを作成し、次の信頼ポリシー`arn:aws:iam::{{444455556666}}:role/Target`を追加します。これにより、ソースロールがロールを引き受けることができます。

   ```
   {
     "Effect": "Allow",
     "Principal": {
        "AWS": "arn:aws:iam::{{111122223333}}:role/Source"
     },
     "Action": "sts:AssumeRole",
     "Condition": {
        "StringEquals": {
           "sts:ExternalId": "arn:aws:aps:{{aws-region}}:{{111122223333}}:scraper/{{scraper-id}}"
         }
     }
   }
   ```

   送信先への書き込みを許可するアクセス許可ポリシーをターゲットロールにアタッチします。送信先が Amazon Managed Service for Prometheus ワークスペースの場合は、[AmazonPrometheusRemoteWriteAccess](https://docs.aws.amazon.com/prometheus/latest/userguide/security-iam-awsmanpol.html) ( を付与) をアタッチします`aps:RemoteWrite`。送信先が Amazon CloudWatch の場合は、データセット`cloudwatch:PutMetricData`に を付与するポリシーをアタッチします。

1. `--role-configuration` オプションを使用してスクレイパーを作成します。

   ```
   aws amp create-scraper \
    --source '{"vpcConfiguration":{"securityGroupIds":["{{sg-security-group-id}}"],"subnetIds":["{{subnet-subnet-id-1}}","{{subnet-subnet-id-2}}"]}}' \
    --exporters '[{"openSearchConfiguration":{"domainArn":"arn:aws:es:{{aws-region}}:{{111122223333}}:domain/{{my-opensearch-domain}}"}}]' \
    --scrape-configuration configurationBlob={{<base64-encoded-blob>}} \
    --destination '{"ampConfiguration":{"workspaceArn":"arn:aws:aps:{{aws-region}}:{{444455556666}}:workspace/{{ws-workspace-id}}"}}' \
    --role-configuration '{"sourceRoleArn":"arn:aws:iam::{{111122223333}}:role/Source", "targetRoleArn":"arn:aws:iam::{{444455556666}}:role/Target"}'
   ```

1. スクレイパーの作成を検証します。

   ```
   aws amp list-scrapers
   ```

## スクレイパーの検出と削除
<a name="prom-opensearch-delete-scraper"></a>

 AWS API または を使用して AWS CLI 、アカウントのスクレイパーを一覧表示したり、削除したりできます。

**注記**  
最新バージョンの AWS CLI または SDK を使用していることを確認します。最新バージョンには、最新の特長と機能に加え、セキュリティアップデートも含まれています。または、常に最新のコマンドラインエクスペリエンスを提供する [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) を自動的に使用します。

アカウント内のすべてのスクレイパーを一覧表示するには、[ListScrapers](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_ListScrapers.html) API オペレーションを使用します。または、 を使用して AWS CLIを呼び出します。

```
aws amp list-scrapers
```

スクレイパーを削除するには、`ListScrapers` オペレーションを使用して削除するスクレイパーの `scraperId` を見つけ、[DeleteScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DeleteScraper.html) オペレーションを使用して削除します。または、 を使用して AWS CLIを呼び出します。

```
aws amp delete-scraper --scraper-id {{scraperId}}
```

## Amazon OpenSearch Service から収集されたメトリクス
<a name="prom-opensearch-metrics"></a>

Amazon OpenSearch Service と統合すると、Amazon Managed Service for Prometheus コレクターは、ドメインの状態とパフォーマンスを記述する Prometheus 互換メトリクスを自動的にスクレイプします。コレクターは数百のメトリクスを出力します。次の表は、各カテゴリの代表的なメトリクスを示しています。次の表の`opensearch_indices_`メトリクスはドメイン全体で集計され、多くの にはプライマリのみのバリアントと合計バリアント (サフィックス `_primary`または ) があります`_total`。コレクターは、インデックス、プレフィックス 、`opensearch_index_stats_`およびプレフィックス のシャードごとのメトリクスごとに同じ統計も出力します`opensearch_indices_shards_`。

### クラスターメトリクス
<a name="opensearch-cluster-metrics"></a>


| メトリクス | 説明/目的 | 
| --- | --- | 
| opensearch\_cluster\_health\_status | クラスターのヘルスステータス (緑、黄色、赤）。 | 
| opensearch\_cluster\_health\_number\_of\_nodes |  クラスター内のノードの数。 | 
| opensearch\_cluster\_health\_number\_of\_data\_nodes | クラスター内のデータノードの数。 | 
| opensearch\_cluster\_health\_active\_primary\_shards | アクティブなプライマリシャードの数。 | 
| opensearch\_cluster\_health\_active\_shards | プライマリシャードとレプリカシャードを含むアクティブなシャードの合計数。 | 
| opensearch\_cluster\_health\_relocating\_shards | ノード間で再配置されるシャードの数。 | 
| opensearch\_cluster\_health\_initializing\_shards | 初期化中のシャードの数。 | 
| opensearch\_cluster\_health\_unassigned\_shards | ノードに割り当てられていないシャードの数。 | 
| opensearch\_cluster\_health\_delayed\_unassigned\_shards | 割り当てが遅れる未割り当てのシャードの数。 | 
| opensearch\_cluster\_health\_number\_of\_pending\_tasks | キューに入れられ、実行を待っているクラスターレベルのタスクの数。 | 
| opensearch\_cluster\_health\_number\_of\_in\_flight\_fetch | 進行中のシャードフェッチリクエストの数。 | 
| opensearch\_cluster\_health\_task\_max\_waiting\_in\_queue\_millis | タスクがキューで待機した最長時間をミリ秒単位で表します。 | 

### ノードのメトリクス
<a name="opensearch-node-metrics"></a>


| メトリクス | 説明/目的 | 
| --- | --- | 
| opensearch\_os\_cpu\_percent | ノード上のオペレーティングシステムが使用する CPU の割合。 | 
| opensearch\_os\_load1 | 過去 1 分間のオペレーティングシステムの負荷平均。コレクターは `opensearch_os_load5`と も出力します`opensearch_os_load15`。 | 
| opensearch\_os\_mem\_used\_bytes | 使用される物理メモリの量、バイト単位。コレクターは `opensearch_os_mem_free_bytes`、`opensearch_os_mem_actual_used_bytes`、および も出力します`opensearch_os_mem_actual_free_bytes`。 | 
| opensearch\_jvm\_memory\_used\_bytes | メモリ領域別 (ヒープと非ヒープ) に使用される JVM メモリのバイト数。関連するメトリクスには、`opensearch_jvm_memory_committed_bytes` および `opensearch_jvm_memory_max_bytes` が含まれます。 | 
| opensearch\_jvm\_gc\_collection\_seconds\_count | JVM ガベージコレクションイベントの総数。ガベージコレクションに費やされた合計時間`opensearch_jvm_gc_collection_seconds_sum`である で を使用します。 | 
| opensearch\_jvm\_uptime\_seconds | JVM の稼働時間を秒単位で表します。 | 
| opensearch\_thread\_pool\_active\_count | 各スレッドプール内のアクティブなスレッドの数。関連するメトリクスには`opensearch_thread_pool_queue_count`、、`opensearch_thread_pool_rejected_count`、および が含まれます`opensearch_thread_pool_completed_count`。 | 
| opensearch\_filesystem\_data\_available\_bytes | ノードで使用可能なディスク容量、バイト単位。関連するメトリクスには、`opensearch_filesystem_data_free_bytes` および `opensearch_filesystem_data_size_bytes` が含まれます。 | 
| opensearch\_filesystem\_io\_stats\_device\_read\_operations\_count | ディスク読み取りオペレーションの数。コレクターは、書き込みおよび合計オペレーション数、読み取りおよび書き込みサイズ ( など) も出力します`opensearch_filesystem_io_stats_device_read_size_kilobytes_sum`。 | 
| opensearch\_process\_cpu\_percent | OpenSearch プロセスで使用される CPU の割合。 | 
| opensearch\_process\_mem\_resident\_size\_bytes | OpenSearch プロセスの常駐メモリサイズ、バイト単位。 | 
| opensearch\_process\_open\_files\_count | OpenSearch プロセスによって開いているファイル記述子の数。 | 
| opensearch\_breakers\_tripped | 各サーキットブレーカーが作動した合計回数。関連するメトリクスには、`opensearch_breakers_estimated_size_bytes` および `opensearch_breakers_limit_size_bytes` が含まれます。 | 
| opensearch\_transport\_rx\_size\_bytes\_total | ノード間のトランスポートレイヤーで受信したデータの合計量をバイト単位で表します。コレクターは `opensearch_transport_tx_size_bytes_total`および パケット数も出力します。 | 
| opensearch\_indexing\_pressure\_current\_all\_in\_bytes | を設定した制限`opensearch_indexing_pressure_limit_in_bytes`として、リクエストのインデックス作成によって消費される現在のメモリをバイト単位で指定します。 | 

### インデックスメトリクス
<a name="opensearch-index-metrics"></a>


| メトリクス | 説明/目的 | 
| --- | --- | 
| opensearch\_indices\_docs | ドキュメントの数。関連するメトリクスには`opensearch_indices_docs_deleted`、、`opensearch_indices_docs_primary`、および が含まれます`opensearch_indices_docs_total`。 | 
| opensearch\_indices\_store\_size\_bytes | ディスク上のインデックスの合計サイズ、バイト単位、 `opensearch_indices_store_size_bytes_primary` および `opensearch_indices_store_size_bytes_total`バリアント。 | 
| opensearch\_indices\_indexing\_index\_total | インデックスが作成されたドキュメントの合計数。インデックス作成のレイテンシー`opensearch_indices_indexing_index_time_seconds_total`には、 で を使用します。 | 
| opensearch\_indices\_indexing\_is\_throttled | インデックス作成が現在スロットリングされているかどうかを示し、合計スロットリング時間`opensearch_indices_indexing_throttle_time_seconds_total`に対して を使用します。 | 
| opensearch\_indices\_search\_query\_total | 検索クエリの合計数。クエリのレイテンシー`opensearch_indices_search_query_time_seconds`には、 で を使用します。 | 
| opensearch\_indices\_search\_fetch\_total | フェッチレイテンシー`opensearch_indices_search_fetch_time_seconds`の を使用したフェッチオペレーションの合計数。 | 
| opensearch\_indices\_get\_total | 取得レイテンシー`opensearch_indices_get_time_seconds`の を含む取得オペレーションの合計数。 | 
| opensearch\_indices\_merges\_total | 完了したセグメントマージの合計数。関連するメトリクスには、`opensearch_indices_merges_current` および `opensearch_indices_merges_total_time_seconds_total` が含まれます。 | 
| opensearch\_indices\_refresh\_total | インデックス更新オペレーションの総数。更新時間は `opensearch_indices_refresh_time_seconds_total`です。 | 
| opensearch\_indices\_flush\_total | インデックスフラッシュオペレーションの総数。フラッシュ時間は `opensearch_indices_flush_time_seconds`です。 | 
| opensearch\_indices\_segments\_count | セグメントの数。コレクターは、セグメントごとのメモリメトリクス ( `opensearch_indices_segments_memory_bytes`や など) も出力します`opensearch_indices_segment_terms_memory_total`。 | 
| opensearch\_indices\_translog\_operations | トランザクションログ内のオペレーションの数。そのサイズ`opensearch_indices_translog_size_in_bytes`には が付きます。 | 
| opensearch\_indices\_fielddata\_memory\_size\_bytes | フィールドデータキャッシュがエビクション`opensearch_indices_fielddata_evictions`に使用するバイト単位のメモリ。 | 
| opensearch\_indices\_query\_cache\_memory\_size\_bytes | クエリキャッシュで使用されるメモリ、バイト単位。関連するメトリクスには、`opensearch_indices_query_cache_count` および `opensearch_indices_query_cache_evictions` が含まれます。 | 
| opensearch\_indices\_request\_cache\_memory\_size\_bytes | リクエストキャッシュで使用されるメモリ、バイト単位。関連するメトリクスには、`opensearch_indices_request_cache_count` および `opensearch_indices_request_cache_evictions` が含まれます。 | 

## 制限事項
<a name="prom-opensearch-limitations"></a>

Amazon OpenSearch Service と Amazon Managed Service for Prometheus の統合には、次の制限があります。
+ Amazon Virtual Private Cloud アクセスを持つ OpenSearch Service ドメインでのみサポートされます。パブリックアクセスを備えたドメインはサポートされていません。
+ スクレイパーは、単一の OpenSearch Service ドメインからメトリクスを収集します。複数のドメインからメトリクスを収集するには、各ドメインごとに個別のスクレイパーを作成します。