

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon CloudWatch 代理程式
<a name="emr-AmazonCloudWatchAgent"></a>

Amazon EMR 上的 Amazon CloudWatch 代理程式是可監控 EMR 叢集中的 Amazon EC2 執行個體的工具。您可在 CloudWatch 中存放和檢視使用 CloudWatch 代理程式收集的指標。如需有關 CloudWatch 代理程式的詳細資訊，請參閱《[Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html)》**。

**注意**  
如果您使用其他 AWS 服務 發佈、查詢或檢視 Amazon CloudWatch 代理程式指標，會產生額外費用。如需定價的詳細資訊，請參閱下列頁面。  
[Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)
[Amazon Managed Service for Prometheus 定價](https://aws.amazon.com/prometheus/pricing/)
[Amazon Managed Grafana 定價](https://aws.amazon.com/grafana/pricing/)
這些指標與 Amazon EMR 在 CloudWatch 命名`AWS/ElasticMapReduce`空間下提供的免費指標不同。如需 CloudWatch 代理程式未發佈之指標的詳細資訊，請參閱[使用 CloudWatch 監控 Amazon EMR 指標](https://docs.aws.amazon.com/emr/latest/ManagementGuide/UsingEMR_ViewingMetrics.html)。

使用 Amazon EMR 7.0 及更高版本，您可以在叢集上安裝自訂版本的 Amazon CloudWatch 代理程式，以從您的 EMR 叢集收集指標。EMR 7.6 及更高版本的執行期角色叢集支援 CloudWatchAgent。代理程式會從叢集中的所有節點收集指標，在主節點上收集指標，然後將指標從該節點發佈到雲端。

您可在主控台中建立新叢集或使用 `create-cluster` API 時，安裝代理程式。如需詳細資訊，請參閱[建立使用 Amazon CloudWatch 代理程式的 EMR 叢集](AmazonCloudWatchAgent-create.md)。根據預設，執行 7.x 版系列的 Amazon EMR 叢集會以 60 秒的間隔將 [34 個系統層級指標](AmazonCloudWatchAgent-metrics.md)發佈至 CloudWatch，但您可以將代理程式設定為發佈不同的指標。另一個選項是將指標發佈至 Amazon Managed Service for Prometheus，您也可以選擇要發佈的指標。對於不同的使用案例和設定，您可以設定代理程式在 CloudWatch 主控台、Amazon Managed Grafana 中或透過 CloudWatch 或 Amazon Managed Service for Prometheus APIs 來檢視和查詢指標。當您使用它們 AWS 服務 來存放和查詢指標時，就會產生費用。

Amazon EMR 上的 CloudWatch 代理程式可以在 Amazon EMR 叢集上發佈下列服務的系統指標和 JMX 指標。
+ Hadoop DataNode
+ Hadoop NameNode
+ Yarn NodeManager
+ Yarn ResourceManager
+ HBase Master – 僅限 Amazon EMR 7.1\$1
+ HBase RegionServer – 僅限 Amazon EMR 7.1\$1
+ HBase ThriftServer – 僅限 Amazon EMR 7.1\$1

如需可用指標以及如何在 Amazon EMR 上設定 CloudWatch 代理程式的詳細資訊，請參閱[為 Amazon EMR 設定 CloudWatch 代理程式](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-config.html)。

以下表格列出了 Amazon EMR 7.x 系列最新版本中包含的 AmazonCloudWatchAgent 版本，以及 Amazon EMR 隨 AmazonCloudWatchAgent 一起安裝的元件。

如需此版本中與 AmazonCloudWatchAgent 一起安裝的元件版本，請參閱[發行版本 7.12.0 元件版本。](emr-7120-release.md)


**emr-7.12.0 的 AmazonCloudWatchAgent 版本資訊**  

| Amazon EMR 發行標籤 | AmazonCloudWatchAgent 版本 | 與 AmazonCloudWatchAgent 一起安裝的元件 | 
| --- | --- | --- | 
| emr-7.12.0 | AmazonCloudWatchAgent 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-hdfs-zkfc, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 

**Topics**
+ [建立使用 Amazon CloudWatch 代理程式的 EMR 叢集](AmazonCloudWatchAgent-create.md)
+ [採用 Amazon EMR 之 CloudWatch 代理程式的預設指標](AmazonCloudWatchAgent-metrics.md)
+ [設定 Amazon EMR 的 CloudWatch 代理程式](AmazonCloudWatchAgent-config.md)
+ [考量和限制](AmazonCloudWatchAgent-considerations.md)
+ [CloudWatch 代理程式版本歷史記錄](AmazonCloudWatchAgent-release-history.md)

# 建立使用 Amazon CloudWatch 代理程式的 EMR 叢集
<a name="AmazonCloudWatchAgent-create"></a>

本節中的程序說明從 AWS 管理主控台 和 使用 Amazon CloudWatch 代理程式在 Amazon EMR 中建立叢集的步驟 AWS CLI。

**Topics**
+ [CloudWatch 代理程式所需的 IAM 許可](#AmazonCloudWatchAgent-permissions)
+ [所需的 CloudWatch 代理程式端點](#AmazonCloudWatchAgent-endpoints)
+ [建立 EMR 叢集](#AmazonCloudWatchAgent-create-cluster)

## CloudWatch 代理程式所需的 IAM 許可
<a name="AmazonCloudWatchAgent-permissions"></a>

CloudWatch 代理程式需要 Amazon EMR 的 Amazon EC2 執行個體設定檔中的 AWS Identity and Access Management (IAM) `cloudwatch:PutMetricData`許可。Amazon EMR 預設角色已具有此許可。您可以使用 從 AWS CLI 建立預設角色`aws emr create-default-roles`。如需詳細資訊，請參閱《Amazon EMR 管理指南》**中的[叢集 EC2 執行個體的服務角色 (EC2 執行個體設定檔)](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-iam-role-for-ec2.html)。

以下範例 IAM 政策包含 `cloudwatch:PutMetricData` 許可：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:PutMetricData"
      ],
      "Resource": [
        "*"
      ],
      "Sid": "AllowCLOUDWATCHPutmetricdata"
    }
  ]
}
```

------

## 所需的 CloudWatch 代理程式端點
<a name="AmazonCloudWatchAgent-endpoints"></a>

若要為私有子網路中的 EMR 叢集，將指標發布至 CloudWatch，請建立 CloudWatch 代理程式端點，並與私有子網路所在的 VPC 建立關聯。

如需每個 CloudWatch 端點的詳細資訊 AWS 區域，請參閱《 *AWS 一般參考指南*》中的 [Amazon CloudWatch 端點和配額](https://docs.aws.amazon.com/general/latest/gr/cw_region.html)。

## 建立 EMR 叢集
<a name="AmazonCloudWatchAgent-create-cluster"></a>

設定與 CloudWatch 代理程式搭配使用的必要許可和端點後，請使用 AWS 管理主控台 或 AWS CLI 來建立已安裝代理程式的新叢集。

------
#### [ Console ]

**在主控台中使用 Amazon CloudWatch 代理程式建立叢集**

1. 導覽至 Amazon EMR 主控台。

1. 選擇 **Create Cluster** (建立叢集)。

1. 在**名稱和應用程式**下，選擇 7.0.0 或更高版本的 Amazon EMR 版本。

1. 在**應用程式套件**下，選取您要安裝至叢集的套件或應用程式，然後在您的選擇中納入 **CloudWatch 代理程式**。

1. 繼續建立叢集以滿足您的使用案例需求。

------
#### [ AWS CLI ]

在 中 AWS CLI，您可以使用 的 `--applications` 參數，將 Amazon CloudWatch 代理程式新增至叢集`create-cluster`。

**從 使用 Amazon CloudWatch 代理程式建立叢集 AWS CLI**
+ 在建立叢集時，請使用類似以下的命令來納入 Amazon CloudWatch 代理程式。使用 EC2 金鑰對名稱取代 `myKey`。

  ```
  aws emr create-cluster --name "Spark cluster with CloudWatch agent" \
  --release-label emr-7.0.0 \
  --applications Name=Spark Name=AmazonCloudWatchAgent \
  --ec2-attributes KeyName=myKey --instance-type m7g.2xlarge \
  --instance-count 3 --use-default-roles
  ```

如需如何搭配 使用 Amazon EMR 的詳細資訊 AWS CLI，請參閱 [AWS CLI 命令參考](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/emr/index.html)。

------

# 採用 Amazon EMR 之 CloudWatch 代理程式的預設指標
<a name="AmazonCloudWatchAgent-metrics"></a>

在 Amazon EMR 上安裝 Amazon CloudWatch 代理程式時，除非您[以不同方式設定代理程式](AmazonCloudWatchAgent-config.md)，否則預設組態會針對叢集中的所有執行個體發布以下系統指標。如需詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的 [CloudWatch 代理程式收集的指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html)。

------
#### [ CPU ]

**CPU 指標**
+ `cpu_usage_active`
+ `cpu_usage_guest`
+ `cpu_usage_guest_nice`
+ `cpu_usage_idle`
+ `cpu_usage_iowait`
+ `cpu_usage_irq`
+ `cpu_usage_nice`
+ `cpu_usage_softirq`
+ `cpu_usage_steal`
+ `cpu_usage_system`
+ `cpu_usage_user`

------
#### [ Disk ]

**磁碟指標**
+ `disk_free`
+ `disk_total`
+ `disk_used`
+ `disk_used_percent`

------
#### [ Memory ]

**記憶體指標**
+ `mem_active`
+ `mem_available`
+ `mem_available_percent`
+ `mem_free`
+ `mem_inactive`
+ `mem_total`
+ `mem_used`
+ `mem_used_percent`
+ `mem_buffered`
+ `mem_cached`

------
#### [ Network IO ]

**網路 IO 指標**
+ `net_bytes_recv`
+ `net_bytes_sent`
+ `net_packets_recv`
+ `net_packets_sent`

------
#### [ Process ]

**程序指標**
+ `processes_running`
+ `processes_total`

------
#### [ Swap ]

**交換指標**
+ `swap_free`
+ `swap_used`
+ `swap_used_percent`

------

根據預設，代理程式會將所有指標發佈至自訂命名空間 下的 CloudWatch`CWAgent`，以及結構描述 `cluster.id`、`instance.id`、`node.type`、 下的 CloudWatch`service.name`。使用以下步驟檢視 CloudWatch 代理程式針對 Amazon EMR 發布的這些預設指標：

1. 導覽至 Amazon CloudWatch 主控台。

1. 選擇**指標**索引標籤，然後選擇**所有指標**。

1. 在**自訂命名空間**下，選取 **`CWAgent`**。然後，選取結構描述：**`cluster.id`、`instance.id`、`node.type`、`service.name`**。

1. 依據您的使用案例需求，繼續從 CloudWatch 介面查詢指標。

Amazon EMR 會將下列標籤連接至每個指標：`["cluster.id", "instance.id', "node.type", "service.name"]`。請針對這些標籤考量以下事項：
+ `cluster.id` 標籤的值是產生指標之 EMR 叢集的 ID。`cluster.id` 標籤的範例值為：`j-123456789ABC`。
+ `instance.id` 標籤的值是產生指標之 EMR 叢集中執行個體的 ID。`instance.id` 標籤的範例值為 `i-01bcf5f140f3355777`。
+ `node.type` 標籤的值代表產生指標之叢集中執行個體的節點類型。此值可以是 `master`、 `core`或 `task`。
+ `service.name` 標籤的值是產生指標之服務的名稱。預設系統指標的預設 `service.name` 值為 `system`。

**注意**  
Amazon EMR 7.0.0 版使用略有不同的指標標籤結構描述。 `cluster.id`是 `jobflow.id`，`node.type`無法使用。 `instance.id` 和 `service.name` 是可用的。

# 設定 Amazon EMR 的 CloudWatch 代理程式
<a name="AmazonCloudWatchAgent-config"></a>

Amazon EMR 7.0.0 及更高版本包括 Amazon CloudWatch 代理程式。下列各節說明如何在 EMR 叢集上設定代理程式，如 中所述[建立使用 Amazon CloudWatch 代理程式的 EMR 叢集](AmazonCloudWatchAgent-create.md)。

**Topics**
+ [設定 Amazon EMR 7.1.0 的 CloudWatch 代理程式](AmazonCloudWatchAgent-config-710.md)
+ [設定 Amazon EMR 7.0.0 的 CloudWatch 代理程式](AmazonCloudWatchAgent-config-700.md)

# 設定 Amazon EMR 7.1.0 的 CloudWatch 代理程式
<a name="AmazonCloudWatchAgent-config-710"></a>

從 Amazon EMR 7.1.0 開始，您可以使用 Amazon EMR 組態 API，將 Amazon CloudWatch 代理程式設定為使用其他系統指標、新增應用程式指標，以及變更指標目的地。如需如何使用 EMR 組態 API 來設定叢集應用程式的詳細資訊，請參閱[設定應用程式](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps.html)。

**注意**  
7.1.0 僅支援重新設定類型 。 `OVERWRITE`如需重新設定類型的詳細資訊，請參閱[重新設定執行個體群組時的考量](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps-running-cluster.html#emr-configure-apps-running-cluster-considerations)事項。

**Topics**
+ [組態結構描述](#AmazonCloudWatchAgent-config-710-config-schema)
+ [系統指標組態範例](#AmazonCloudWatchAgent-config-710-system-examples)
+ [應用程式指標組態範例](#AmazonCloudWatchAgent-config-710-application-examples)
+ [Amazon Managed Service for Prometheus 範例](#AmazonCloudWatchAgent-config-710-prometheus-examples)

## 組態結構描述
<a name="AmazonCloudWatchAgent-config-710-config-schema"></a>

`emr-metrics` 具有下列分類：
+ `emr-system-metrics` — 設定系統指標，例如 CPU、磁碟和記憶體。
+ `emr-hadoop-hdfs-datanode-metrics` — 設定 Hadoop DataNode JMX 指標
+ `emr-hadoop-hdfs-namenode-metrics` — 設定 Hadoop NameNode JMX 指標
+ `emr-hadoop-yarn-nodemanager-metrics` — 設定 Yarn NodeManager JMX 指標
+ `emr-hadoop-yarn-resourcemanager-metrics` — 設定 Yarn ResourceManager JMX 指標
+ `emr-hbase-master-metrics` — 設定 HBase Master JMX 指標
+ `emr-hbase-region-server-metrics` — 設定 HBase Region Server JMX 指標
+ `emr-hbase-rest-server-metrics` — 設定 HBase REST Server JMX 指標
+ `emr-hbase-thrift-server-metrics` — 設定 HBase Thrift Server JMX 指標

下表說明所有分類的可用屬性和組態。

**emr-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics\$1destination | 選用 | 決定叢集指標是否發佈至 Amazon CloudWatch 或 Amazon Managed Service for Prometheus。 | 「CLOUDWATCH」 | "CLOUDWATCH"、"PROMETHEUS" | 此屬性不區分大小寫。例如，「Cloudwatch」與「CLOUDWATCH」相同。 | 
| prometheus\$1endpoint | 選用 | 如果 metrics\$1destination 設為「PROMETHEUS」，此屬性會將 CloudWatch 代理程式設定為將指標傳送至提供的 Amazon Managed Service for Prometheus 遠端寫入端點。 | N/A | 任何有效的 Amazon Managed Service for Prometheus 遠端寫入 URL。遠端寫入 URL 格式為 <pre>https://aps-workspaces.<region>.amazonaws.com/workspaces/<workspace_id>/api/v1/remote_write</pre> | 如果 metrics\$1destination 設定為 "PROMETHEUS"，則此欄位為必要欄位。如果您未提供金鑰或值為空字串，佈建將會失敗。 | 

**emr-system-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics\$1collection\$1interval | 選用 | 從 CloudWatch 代理程式收集和發佈以秒為單位的指標的頻率。 | "60" | 指定秒數的字串。僅接受整數。 | 您可以使用個別指標群組的 屬性覆寫此metrics\$1collection\$1interval屬性。 | 

**emr-system-metrics 組態**

------
#### [ cpu ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的 CPU 指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含cpu\$1字首的有效 CPU 指標名稱逗號分隔清單，例如 usage\$1active和 cpu\$1time\$1idle。如需有效[指標，請參閱 CloudWatch 代理程式收集的](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)指標。 | 指定空字串表示不發佈任何 CPU 指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應在幾秒內收集和發佈 CPU 指標的頻率。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會覆寫 CPU 指標的全域metrics\$1collection\$1interval屬性。 | 
| drop\$1original\$1metrics | 選用 | 不發佈未彙總指標的 CPU 指標清單。 | 未發佈任何未彙總的 CPU 指標。 | 以逗號分隔的 CPU 指標清單，這些指標也會在指標屬性中指定。空字串表示發佈所有 CPU 指標。 | CloudWatch 代理程式會依叢集 ID、執行個體 ID、節點類型和服務名稱彙總所有指標。根據預設，CloudWatch 代理程式不會為具有多個資源的指標發佈每個資源指標。 | 
| resources | 選用 | 決定代理程式是否發佈每個核心指標。 | "\$1" | "\$1" 啟用每個核心指標。"" 停用每個核心指標。 | CloudWatch 代理程式只會針對未在 中捨棄的 CPU 指標發佈每個核心指標drop\$1original\$1metrics。 | 

------
#### [ disk ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的磁碟指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含disk\$1字首的有效磁碟指標名稱逗號分隔清單，例如 disk\$1total和 used\$1percent。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何磁碟指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式收集和發佈磁碟指標的頻率，以秒為單位。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對磁碟指標覆寫全域metrics\$1collection\$1interval屬性。 | 
| drop\$1original\$1metrics | 選用 | 不發佈未彙總指標的磁碟指標清單。 | 未發佈任何未彙總的磁碟指標。 | 以逗號分隔的磁碟指標清單，也會在指標屬性中指定。空字串表示發佈所有磁碟指標。 | CloudWatch 代理程式會依叢集 ID、執行個體 ID、節點類型和服務名稱彙總所有指標。根據預設，CloudWatch 代理程式不會為具有多個資源的指標發佈每個資源指標。 | 
| resources | 選用 | 決定代理程式是否發佈per-mount-point指標。 | "\$1" | "\$1" 表示所有掛載點，"" 表示沒有掛載點，或以逗號分隔的掛載點清單。例如 "/,/emr"。 | CloudWatch 代理程式只會針對未在 中捨棄的磁碟指標發佈per-mount-point指標drop\$1original\$1metrics。 | 

------
#### [ diskio ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的磁碟 IO 指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含diskio\$1字首的有效磁碟 IO 指標名稱逗號分隔清單，例如 diskio\$1reads和 writes。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何磁碟 IO 指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應該收集和發佈磁碟 IO 指標的頻率，以秒為單位。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對磁碟 IO 指標覆寫全域metrics\$1collection\$1interval屬性。 | 
| drop\$1original\$1metrics | 選用 | 不發佈未彙總指標的磁碟 IO 指標清單。 | 未發佈任何未彙總的磁碟 IO 指標。 | 以逗號分隔的磁碟 IO 指標清單，也會在指標屬性中指定。空字串表示發佈所有磁碟 IO 指標。 | CloudWatch 代理程式會依叢集 ID、執行個體 ID、節點類型和服務名稱彙總所有指標。根據預設，CloudWatch 代理程式不會為具有多個資源的指標發佈每個資源指標。 | 
| resources | 選用 | 決定代理程式是否發佈每個裝置指標。 | "\$1" | "\$1" 表示所有儲存裝置，"" 表示沒有儲存裝置，或以逗號分隔的裝置名稱清單。例如 "nvme0n1,nvme1n1"。 | CloudWatch 代理程式只會針對未在 中捨棄的磁碟 IO 指標，發佈每個裝置指標drop\$1original\$1metrics。 | 

------
#### [ mem ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 要收集之代理程式的記憶體指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含mem\$1字首的有效記憶體指標名稱逗號分隔清單，例如 mem\$1available和 available\$1percent。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何記憶體指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應在幾秒內收集和發佈記憶體指標的頻率。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對記憶體指標覆寫全域metrics\$1collection\$1interval屬性。 | 

------
#### [ net ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 要收集之代理程式的網路指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含net\$1字首的有效網路指標名稱逗號分隔清單，例如 net\$1packets\$1sent和 packets\$1recv。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何網路指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應在幾秒內收集和發佈網路指標的頻率。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對網路指標覆寫全域metrics\$1collection\$1interval屬性。 | 
| drop\$1original\$1metrics | 選用 | 不發佈未彙總指標的網路指標清單。 | 未發佈任何未彙總的網路指標。 | 以逗號分隔的網路指標清單，也會在指標屬性中指定。空字串表示發佈所有網路指標。 | CloudWatch 代理程式會依叢集 ID、執行個體 ID、節點類型和服務名稱彙總所有指標。根據預設，CloudWatch 代理程式不會為具有多個資源的指標發佈每個資源指標。 | 
| resources | 選用 | 決定代理程式是否發佈每個介面的指標。 | "\$1" | "\$1" 表示所有網路介面，"" 表示沒有網路介面，或以逗號分隔的介面名稱清單。例如 "eth0,eth1"。 | CloudWatch 代理程式只會針對未在 中捨棄的網路指標發佈每個介面指標drop\$1original\$1metrics。 | 

------
#### [ netstat ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的網路統計資料指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 有效記憶體指標名稱的逗號分隔清單，包含或不包含netstat\$1字首，例如 tcp\$1listen和 netstat\$1udp\$1socket。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何網路統計資料指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應在幾秒內收集和發佈網路統計資料指標的頻率。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對網路統計資料指標覆寫全域metrics\$1collection\$1interval屬性。 | 

------
#### [ processes ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的程序指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含processes\$1字首的有效記憶體指標名稱逗號分隔清單，例如 processes\$1running和 total。如需有效[指標，請參閱 CloudWatch 代理程式收集的](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)指標。 | 指定空字串表示不發佈任何程序指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式應在幾秒內收集和發佈系統程序指標的頻率。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對系統程序指標覆寫全域metrics\$1collection\$1interval屬性。 | 

------
#### [ swap ]


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 備註 | 
| --- | --- | --- | --- | --- | --- | 
| metrics | 選用 | 代理程式要收集的交換指標清單。 | 請參閱 [ CloudWatch 代理程式與 Amazon EMR 的預設指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-metrics.html) | 含或不含swap\$1字首的有效記憶體指標名稱逗號分隔清單，例如 swap\$1free和 used\$1percent。如需有效[指標，請參閱 CloudWatch 代理程式收集](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html#linux-metrics-enabled-by-CloudWatch-agent)的指標。 | 指定空字串表示不發佈任何交換指標。 | 
| metrics\$1collection\$1interval | 選用 | 代理程式收集和發佈交換指標的頻率，以秒為單位。 | 全域 的值metrics\$1collection\$1interval。 | 指定秒數的字串。僅接受整數。 | 此值只會針對交換指標覆寫全域metrics\$1collection\$1interval屬性。 | 

------

**emr-hadoop-hdfs-datanode-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=DataNode,name=DataNodeActivity。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 BlocksCached,BlocksRead。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 Hadoop DataNode 指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hadoop-hdfs-namenode-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=NameNode,name=FSNamesystem。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 BlockCapacity,CapacityUsedGB。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 Hadoop NameNode 指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hadoop-yarn-nodemanager-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=NodeManager,name=NodeManagerMetrics。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 MaxCapacity,AllocatedGB。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 Hadoop YARN NodeManager 指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hadoop-yarn-resourcemanager-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=ResourceManager,name=PartitionQueueMetrics。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 MaxCapacity,MaxCapacityVCores。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 Hadoop YARN ResourceManager 指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hbase-master-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=HBase,name=Master,sub=AssignmentManager。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 AssignFailedCount,AssignSubmittedCount。 | 
| otel.metric.export.interval | 選用 | 收集 HBase Master 指標的頻率，以毫秒為單位。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hbase-region-server-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=HBase,name=RegionServer,sub=IPC。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 numActiveHandler,numActivePriorityHandler。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 HBase 區域伺服器指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hbase-rest-server-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=HBase,name=REST。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 successfulPut,successfulScanCount。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 HBase Rest Server 指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

**emr-hbase-thrift-server-metrics 屬性**


| 屬性 | 必要 | Description | 預設值 | 可能的值 | 
| --- | --- | --- | --- | --- | 
| <custom\$1bean\$1name> | 選用 | N/A | CloudWatch 代理程式應從中收集指標的 MBean，例如 Hadoop:service=HBase,name=Thrift,sub=ThriftOne。您可以在 Amazon EMR 7.0 版[的範例 JMX YAML 檔案](https://github.com/aws-samples/aws-emr-utilities/tree/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings)中找到範例 MBean 名稱及其對應的指標。 | 包含與 MBean 相關聯之指標逗號分隔清單的字串。例如 BatchGet\$1max,BatchGet\$1mean。 | 
| otel.metric.export.interval | 選用 | 以毫秒為單位收集 HBase Thrift 伺服器指標的頻率。 | "60000" | 指定毫秒數的字串。僅接受整數。 | 

## 系統指標組態範例
<a name="AmazonCloudWatchAgent-config-710-system-examples"></a>

下列範例示範如何設定 CloudWatch 代理程式以停止匯出所有系統指標。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {},
    "Configurations": [
      {
        "Classification": "emr-system-metrics",
        "Properties": {},
        "Configurations": []
      }
    ]
  }
]
```

下列範例會將 CloudWatch 代理程式設定為匯出預設系統指標。這樣做是將代理程式重設回僅匯出預設系統指標的快速方法，前提是您已至少重新設定系統指標一次。此重設也會移除之前重新設定的任何應用程式指標。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {},
    "Configurations": []
  }
]
```

下列範例會將叢集設定為匯出 `cpu`、 `mem`和 `disk`指標。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {},
    "Configurations": [
      {
        "Classification": "emr-system-metrics",
        "Properties": {
          "metrics_collection_interval": "20"
        },
        "Configurations": [
          {
            "Classification": "cpu",
            "Properties": {
              "metrics": "cpu_usage_guest,cpu_usage_idle",
              "metrics_collection_interval": "30",
              "drop_original_metrics": "cpu_usage_guest"
            }
          },
          {
            "Classification": "mem",
            "Properties": {
              "metrics": "mem_active"
            }
          },
           {
            "Classification": "disk",
            "Properties": {
              "metrics": "disk_used_percent",
              "resources": "/,/mnt",
              "drop_original_metrics": ""
            }
          }
        ]
      }
    ]
  }
]
```

先前的範例組態具有下列屬性：
+ 代理程式每 30 秒會收集所有 CPUs的`cpu_guest`指標。您可以在 CloudWatch 命名空間 下找到彙總指標`CWAgent > cluster.id, instance.id, node.type, service.name`。
+ 代理程式每 30 秒會收集所有 CPUs的`cpu_idle`指標。您可以在 CloudWatch 命名空間 下找到彙總指標`CWAgent > cluster.id, instance.id, node.type, service.name`。代理程式也會收集每個 CPU 指標。您可以在相同的命名空間中找到它們。代理程式會收集此指標，因為 `drop_original_metrics` 屬性不包含 `cpu_idle`，因此代理程式不會忽略指標。
+ 代理程式每 20 秒收集一次`mem_active`指標。您可以在 CloudWatch 命名空間 下找到彙總指標`CWAgent > cluster.id, instance.id, node.type, service.name`。
+ 代理程式每 20 秒會收集 `/`和`/mnt`磁碟掛載的`disk_used_percent`指標。您可以在 CloudWatch 命名空間 下找到彙總指標`CWAgent > cluster.id, instance.id, node.type, service.name`。代理程式也會收集每個掛載指標。您可以在相同的命名空間中找到它們。代理程式會收集此指標，因為 `drop_original_metrics` 屬性不包含 `disk_used_percent`，因此代理程式不會忽略指標。

## 應用程式指標組態範例
<a name="AmazonCloudWatchAgent-config-710-application-examples"></a>

下列範例會將 CloudWatch 代理程式設定為停止匯出 Hadoop Namenode 服務的指標。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {},
    "Configurations": [
      {
        "Classification": "emr-hadoop-hdfs-namenode-metrics",
        "Properties": {},
        "Configurations": []
      }
    ]
  }
]
```

下列範例會設定叢集以匯出 Hadoop 應用程式指標。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {},
    "Configurations": [
      {
        "Classification": "emr-hadoop-hdfs-namenode-metrics",
        "Properties": {
          "Hadoop:service=NameNode,name=FSNamesystem": "BlockCapacity,CapacityUsedGB",
          "otel.metric.export.interval": "20000" 
        },
        "Configurations": []
      },
       {
        "Classification": "emr-hadoop-hdfs-datanode-metrics",
        "Properties": {
          "Hadoop:service=DataNode,name=JvmMetrics": "MemNonHeapUsedM",
          "otel.metric.export.interval": "30000" 
        },
        "Configurations": []
      },
       {
        "Classification": "emr-hadoop-yarn-resourcemanager-metrics",
        "Properties": {
          "Hadoop:service=ResourceManager,name=CapacitySchedulerMetrics": "AllocateNumOps,NodeUpdateNumOps"
        },
        "Configurations": []
      }
    ]
  }
]
```

上一個範例具有下列屬性：
+ 每 20 秒，代理程式會從執行 Hadoop Namenode 服務的執行個體收集 `BlockCapacity`和 `CapacityUsedGB`指標。
+ 每 30 秒，代理程式會從執行 Hadoop Datanode 服務的執行個體收集`MemNonHeapUsedM`指標。
+ 代理程式每 30 秒會從執行 Hadoop YARN ResourceManaager 的執行個體收集 `AllocateNumOps`和 `NodeUpdateNumOps`指標。

## Amazon Managed Service for Prometheus 範例
<a name="AmazonCloudWatchAgent-config-710-prometheus-examples"></a>

下列範例示範如何設定 CloudWatch 代理程式，將指標匯出至 Amazon Managed Service for Prometheus。

如果您目前正在將指標匯出至 Amazon Managed Service for Prometheus，並想要重新設定叢集的指標，並繼續將指標匯出至 Amazon Managed Service for Prometheus，則必須包含 屬性 `metrics_destination`和 `prometheus_endpoint`。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {
      "metrics_destination": "prometheus",
      "prometheus_endpoint": "http://amp-workspace/api/v1/remote_write"
    },
    "Configurations": []
  }
]
```

若要使用 CloudWatch 代理程式將指標匯出至 CloudWatch，請使用下列範例。

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {
      "metrics_destination": "cloudwatch"
    },
    "Configurations": []
  }
]
```

**注意**  
CloudWatch 代理程式具有可重新命名特定屬性的 Prometheus 匯出工具。針對預設指標標籤，Amazon Managed Service for Prometheus 會使用底線字元來取代 Amazon CloudWatch 使用的期間。如果您使用 Amazon Managed Grafana 視覺化 Amazon Managed Service for Prometheus 中的預設指標，標籤會顯示為 `cluster_id`、`instance_id`、 `node_type`和 `service_name`。

# 設定 Amazon EMR 7.0.0 的 CloudWatch 代理程式
<a name="AmazonCloudWatchAgent-config-700"></a>

您可以設定 Amazon CloudWatch 代理程式，以使用[預設 CloudWatch 代理程式組態](AmazonCloudWatchAgent-metrics.md)提供的系統指標以外的其他系統指標。7.0.0 的組態需要使用引導動作，我們已在以下各節中提供相關範例。在即將發行的版本中，Amazon EMR 將透過 Amazon EMR API 提供其他組態選項。

**Topics**
+ [透過 Amazon EMR 7.0.0 設定其他系統指標](#AmazonCloudWatchAgent-config-700-add-metrics)
+ [透過 Amazon EMR 7.0.0 設定應用程式指標](#AmazonCloudWatchAgent-config-700-app-metrics)
+ [使用 Amazon EMR 7.0.0 將 Amazon Managed Service for Prometheus 設定為指標的雲端儲存空間](#AmazonCloudWatchAgent-config-700-prometheus)

## 透過 Amazon EMR 7.0.0 設定其他系統指標
<a name="AmazonCloudWatchAgent-config-700-add-metrics"></a>

使用以下步驟設定代理程式，以在 Amazon EMR 7.0.0 中使用不同組的系統指標：

1. 在您要存放指定 CloudWatch 代理程式指標之組態檔案的 Amazon S3 帳戶中，建立或選擇儲存貯體。

1. 使用指定的偏好指標來建立 `emr-amazon-cloudwatch-agent.json` 組態檔案。為此，請使用[建立 CloudWatch 代理程式組態檔案](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-cloudwatch-agent-configuration-file.html)中所述的其中一個方法。如需有關 CloudWatch 代理程式組態檔案之結構的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》中的**[手動建立或編輯 CloudWatch 代理程式組態檔案](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html)。

1. 接下來，請導覽至 GitHub 上的 **aws-emr-utilities** 儲存庫，然後下載以下系統指標指令碼：
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/system-metrics/install_system_metrics_launcher.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/system-metrics/install_system_metrics_launcher.sh)**：下載後在背景中執行 `install_system_metrics.sh` 的指令碼，讓節點可完成引導。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/system-metrics/install_system_metrics.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/system-metrics/install_system_metrics.sh)**：此指令碼會等待其運作之執行個體，以完成引導，然後在 JSON 檔案中下載並套用組態。

1. 開啟各個 SH 檔案，並使用步驟 1 中儲存貯體的名稱取代 `amzn-s3-demo-bucket`。

1. 將一個 JSON 檔案和兩個 SH 檔案上傳至 S3 儲存貯體。

1. 現在，您可導覽至 Amazon EMR 主控台，並使用 CloudWatch 代理程式建立新的叢集。在左側導覽窗格中的 **EMR on EC2** 下，選取**叢集**，然後選取**建立叢集**。

1. 在**名稱和應用程式**區段下，選擇 7.0.0 或更高版本的 Amazon EMR 版本。

1. 在**應用程式套件**下，選取您要安裝至叢集的套件或應用程式，然後在您的選擇中納入 **Amazon CloudWatch 代理程式**。

1. 在**引導動作**區段中，選取**新增**。
   + 在**名稱**中插入 **install\$1system\$1metrics\$1launcher.sh**。
   + 在**指令碼位置**中插入 **s3://*amzn-s3-demo-bucket*/install\$1system\$1metrics\$1launcher.sh**。使用 S3 儲存貯體的路徑取代 `amzn-s3-demo-bucket`。
   + 將**引數**區塊留空。

1. 選取**新增引導操作**。

1. 繼續建立叢集以滿足您的工作負載需求。

在叢集啟動時，CloudWatch 代理程式會將您在組態檔案中指定的系統指標發布至 CloudWatch。

## 透過 Amazon EMR 7.0.0 設定應用程式指標
<a name="AmazonCloudWatchAgent-config-700-app-metrics"></a>

除了系統指標之外，您也可設定 Amazon CloudWatch 代理程式，以發布 HDFS 和 YARN 的應用程式指標。使用以下步驟設定代理程式，以發布應用程式指標：

1. 在您要存放指定 CloudWatch 代理程式指標之組態檔案的 Amazon S3 帳戶中，建立或選擇儲存貯體。

1. 接下來，請導覽至 GitHub 上的 **aws-emr-utilities** 儲存庫，然後下載以下指令碼：
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/install_app_metrics_launcher.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/install_app_metrics_launcher.sh)**：下載後在背景中執行 `install_app_metrics.sh` 的指令碼，讓節點可完成引導。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/install_app_metrics.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/install_app_metrics.sh)**：此指令碼會等待其運作之執行個體，以完成引導，然後在 YAML 檔案 (您將於後續步驟中下載) 中下載並套用組態。

1. 開啟各個檔案，並使用步驟 1 中儲存貯體的名稱取代 `amzn-s3-demo-bucket`。

1. 接下來，請下載以下 YAML 映射檔案。如需有關這些 YAML 檔案結構化方式的詳細資訊，請參閱 *OpenTelemetry Instrumentation for Java* GitHub 儲存庫中的 [https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/jmx-metrics/javaagent](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/jmx-metrics/javaagent)。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/datanode-metrics.yaml](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/datanode-metrics.yaml)**：Hadoop DataNode 指標的組態。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/namenode-metrics.yaml](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/namenode-metrics.yaml)**：Hadoop NameNode 指標的組態。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/nodemanager-metrics.yaml](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/nodemanager-metrics.yaml)**：Yarn NodeManager 指標的組態。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/resourcemanager-metrics.yaml](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/application-metrics/mappings/resourcemanager-metrics.yaml)**：Yarn ResourceManager 指標的組態。

1. 將兩個 SH 檔案和四個 YAML 檔案上傳至 S3 儲存貯體。

1. 現在，您可導覽至 Amazon EMR 主控台，並使用 CloudWatch 代理程式建立新的叢集。在左側導覽窗格中的 **EMR on EC2** 下，選取**叢集**，然後選取**建立叢集**。

1. 在**名稱和應用程式**區段下，選擇 7.0.0 或更高版本的 Amazon EMR 版本。

1. 在**應用程式套件**下，選取您要安裝至叢集的套件或應用程式的自訂群組，然後在您的選擇中納入 **CloudWatch 代理程式**。

1. 在**引導動作**區段中，選取**新增**。
   + 在**名稱**中插入 **install\$1app\$1metrics\$1launcher.sh**。
   + 在**指令碼位置**中插入 **s3://*amzn-s3-demo-bucket*/install\$1app\$1metrics\$1launcher.sh**。使用 S3 儲存貯體的路徑取代 `amzn-s3-demo-bucket`。
   + 將**引數**區塊留空。

1. 選取**新增引導操作**。

1. 繼續建立叢集以滿足您的工作負載需求。

在叢集啟動時，CloudWatch 代理程式會將您隨系統指標指定的應用程式指標發布至 CloudWatch。

## 使用 Amazon EMR 7.0.0 將 Amazon Managed Service for Prometheus 設定為指標的雲端儲存空間
<a name="AmazonCloudWatchAgent-config-700-prometheus"></a>

您可設定 Amazon CloudWatch 代理程式，以將指標發布至 Amazon Managed Service for Prometheus (而非 CloudWatch)。

**注意**  
您可將指標從 Amazon CloudWatch 代理程式發布至 Amazon Managed Service for Prometheus 或 Amazon CloudWatch，但無法將指標發布至同一個叢集的兩個服務。

若要設定代理程式將指標發佈至 Amazon Managed Service for Prometheus，您必須將 `aps:RemoteWrite` AWS Identity and Access Management (IAM) 許可新增至 Amazon EMR 的 Amazon EC2 執行個體描述檔。下列政策範例包含必要許可：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "aps:RemoteWrite"
      ],
      "Resource": [
        "*"
      ],
      "Sid": "AllowAPSRemotewrite"
    }
  ]
}
```

------

**使用 EMR 叢集上的 CloudWatch 代理程式，以將指標發布至 Amazon Managed Service for Prometheus**

在服務政策具有正確許可後，請使用以下步驟啟動叢集，該叢集會使用 CloudWatch 代理程式將指標發布至 Amazon Managed Service for Prometheus。

1. 使用 AWS 管理主控台 或 AWS CLI 建立 Amazon Managed Service for Prometheus 工作區。如需詳細資訊，請參閱 *Amazon Managed Service for Prometheus User Guide* 中的 [Create a workspace](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html)。

1. 在您要存放將 Amazon Managed Service for Prometheus 指定為雲端儲存空間之啟動檔案的 Amazon S3 帳戶中，建立或選擇儲存貯體。

1. 接下來，請導覽至 GitHub 上的 **aws-emr-utilities** 儲存庫，然後下載以下指令碼：
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/prometheus/add_prometheus_endpoint_launcher.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/prometheus/add_prometheus_endpoint_launcher.sh)**：下載後在背景中執行 `add_prometheus_endpoint.sh` 的指令碼，讓節點可完成引導。
   + **[https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/prometheus/add_prometheus_endpoint.sh](https://github.com/aws-samples/aws-emr-utilities/blob/main/applications/cloudwatch-agent/configuration/7.0/prometheus/add_prometheus_endpoint.sh)**：此指令碼會等待其運作之執行個體，以完成引導，然後設定 CloudWatch 代理程式以發布至 Amazon Managed Service for Prometheus 端點，其為您在啟動叢集時提供作為引數的端點。

1. 開啟各個檔案，並使用步驟 2 中儲存貯體的名稱取代 `amzn-s3-demo-bucket`。

1. 使用 AWS CLI 建立具有`add_prometheus_endpoint_launcher.sh`引導操作的 EMR 叢集。在以下命令中，使用包含引導動作的儲存貯體取代 `amzn-s3-demo-bucket`，並使用適合 Amazon Managed Service for Prometheus 工作區的遠端寫入端點取代 `managedpro-remote-write-workspace-url`。請務必指定 `emr-7.0.0` 或更高版本的 Amazon EMR 發行標籤。

   ```
   aws emr create-cluster --name managedpro-cluster \
       --release-label emr-7.0.0 \
       --applications Name=Hadoop Name=AmazonCloudWatchAgent \
       --ec2-attributes KeyName=myKey --instance-type m7g.2xlarge \
       --instance-count 3 --use-default-roles
      --bootstrap-actions Name='Add Prometheus Endpoint',Path=s3://amzn-s3-demo-bucket/add_prometheus_endpoint_launcher.sh,Args='managedpro-remote-write-workspace-url'
   ```

在叢集啟動時，CloudWatch 代理程式會將其收集的指標發布至 Amazon Managed Service for Prometheus。

**將 Amazon Managed Service for Prometheus 用作 Amazon Managed Grafana 的資料來源**

在 Amazon EMR 將叢集指標發布至 Amazon Managed Service for Prometheus 後，您便可使用以下步驟利用 Amazon Managed Grafana 將指標視覺化：

1. 使用 AWS 管理主控台 建立具有適當許可的 Amazon Managed Grafana 工作區和使用者。如需詳細資訊，請參閱 *Amazon Managed Grafana User Guide* 中的 [Create a workspace](https://docs.aws.amazon.com/grafana/latest/userguide/AMG-create-workspace.html)。

1. 將您的 Amazon Managed Service for Prometheus 工作區作為資料來源新增至 Amazon Managed Grafana。如需詳細資訊，請參閱 *Amazon Managed Grafana User Guide* 中的 [Use AWS data source configuration to add Amazon Managed Service for Prometheus as a data source](https://docs.aws.amazon.com/grafana/latest/userguide/AMP-adding-AWS-config.html)。

**注意**  
CloudWatch 代理程式具有可重新命名特定屬性的 Prometheus 匯出工具。針對預設指標標籤，Amazon Managed Service for Prometheus 會使用底線字元來取代 Amazon CloudWatch 使用的期間。因此，如果您在 Amazon Managed Service for Prometheus 中使用 Amazon Managed Grafana 來視覺化預設指標，則標籤會顯示為 `jobflow_id`、`instance_id` 和 `service_name`。  
此外，CloudWatch 代理程式發布至 Amazon Managed Service for Prometheus 的任何**應用程式**指標，皆會使用 `job` 標籤而非 `service_name`。然而，**系統**指標仍會繼續使用 `service_name` 標籤。

# 考量和限制
<a name="AmazonCloudWatchAgent-considerations"></a>
+ 原生 Amazon CloudWatch 代理程式可用於您使用 Amazon EMR 版本 7.0.0 及更高版本建立的叢集。
+ Amazon EMR 7.0.0 中的 CloudWatch 代理程式組態需使用[引導動作](AmazonCloudWatchAgent-config-700.md)。在即將發行的版本中，Amazon EMR 將透過 Amazon EMR API 提供其他組態選項。
+ 如果您已透過其他方法部署 CloudWatch 代理程式，例如建立叢集的區域中的代理程式 (SSM 代理程式），則無法安裝 Amazon EMR CloudWatch 代理程式。 AWS Systems Manager 如此一來將導致叢集發生錯誤並終止。
+ CloudWatch GetMetricData API 支援每個請求最多 500 個指標。如果您的 Amazon EMR 叢集在執行個體群組或機群中包含超過 250 個節點，EMR 中 CloudWatch 內嵌儀表板中的對應圖形會顯示空白，並顯示錯誤 **太多指標**，因為這些指標在**叢集概觀**儀表板中每個指標需要兩個資料點。不過，透過篩選**核心**或**任務執行個體群組** （或機群） 儀表板，您可以檢視每個執行個體群組或機群最多 500 個節點的圖形。這是因為這些不需要每個指標兩個資料點。除了每個執行個體群組或機群 500 個節點之外，這些儀表板中的指標也會發生**太多**指標錯誤。

# CloudWatch 代理程式版本歷史記錄
<a name="AmazonCloudWatchAgent-release-history"></a>

以下表格列出了 Amazon EMR 的每個發行版本中包含的 AmazonCloudWatchAgent 版本，以及與應用程式一起搭配安裝的元件。如需每個發行版本中的元件版本，請參閱 [Amazon EMR 7.x 發行版本](emr-release-7x.md)、[Amazon EMR 6.x 發行版本](emr-release-6x.md) 或 [Amazon EMR 5.x 發行版本](emr-release-5x.md) 中適用於您發行版本的「元件版本」一節。


**AmazonCloudWatchAgent 版本資訊**  

| Amazon EMR 發行標籤 | AmazonCloudWatchAgent 版本 | 與 AmazonCloudWatchAgent 一起安裝的元件 | 
| --- | --- | --- | 
| emr-7.12.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-hdfs-zkfc, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.11.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-hdfs-zkfc, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.10.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.9.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.8.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.7.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.6.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.5.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.4.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.3.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.2.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.1.0 | 1.300032.2-amzn-0 | adot-java-agent, emrfs, emr-amazon-cloudwatch-agent, emr-ddb, emr-goodies, emr-kinesis, emr-s3-dist-cp, hadoop-client, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-httpfs-server, hadoop-kms-server, hadoop-mapred, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server | 
| emr-7.0.0 | 1.300031.1-amzn-0 | adot-java-agent, emr-amazon-cloudwatch-agent | 