

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

# 使用 Amazon CloudWatch 監控 EMR HBase
<a name="emr-hbase-cw"></a>

從 EMR 7.0 開始，Amazon EMR 會提供 Amazon CloudWatch Agent 將指標傳送至 CloudWatch 或 Prometheus，以取代 Ganglia 監控系統。您可以在 [Amazon CloudWatch 代理程式組態指南](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-config-700.html)中找到更多詳細資訊。

EMR 7.0 Amazon CloudWatch 代理程式提供基本整合，並設定所需的手動工作，例如下載元件和使用引導操作。不過，從 EMR 7.1 開始，程序會簡化。在 EMR 7.1 中使用 Amazon CloudWatch Agent 可讓您輕鬆監控系統層級和應用程式特定的指標，包括 HBase 指標。透過使用 EMR 組態 API，您可以快速設定和自訂指標收集程序，並選擇將資料傳送到 Amazon CloudWatch 或 Prometheus 的位置。此彈性可協助您密切關注 HBase 叢集，確保其順暢且有效率地執行。

使用 EMR 組態 API 來處理整個設定，使程序更順暢。EMR 7.1 中的 CloudWatch Agent 支援三種主要的指標類型：
+ **系統指標** – 這些包括系統效能的關鍵指標，例如：CPU 用量、磁碟用量、記憶體用量、網路 I/O、處理程序和交換用量。
+ **Hadoop 協助程式指標** – 這些指標與 Hadoop 的各種元件相關，包括：DataNode 指標、NameNode 指標、YARN NodeManager 指標和 YARN ResourceManager 指標。
+ **HBase 指標** – 這些指標提供 HBase 效能的洞見：HBase Master 指標、HBase Region Server 指標、HBase REST Server 指標和 HBase Thrift Server 指標。

------
#### [ Using the AWS CLI ]

Hadoop 和 HBase 的所有指標都是 JMX 型，這表示它們使用 Java 管理延伸模組來提供詳細的洞見。以下是您可以設定 Amazon CloudWatch Agent 來監控 HBase 的方式：
+ 使用 Amazon CloudWatch Agent 建立叢集之前，請參閱[先決條件](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-create.html)。使用與此清單之後出現的範例類似的`create-cluster`命令。
+ 請參閱 HBase 叢集支援的[組態](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/AmazonCloudWatchAgent-config.html)。
+ 如需設定 HBase 監控的範例組態，請參閱下列範例。請參閱`--configuration`輸入的範例組態。

```
aws emr create-cluster --name "HBase cluster with CloudWatch agent" \
--release-label emr-7.1.0 \
--applications Name=HBase Name=AmazonCloudWatchAgent \
--ec2-attributes KeyName=myKey --instance-type m7g.2xlarge \
--configurations file://./configurations.json \  
--instance-count 3 --use-default-roles
```

如需指標的 JSON 範例組態詳細資訊，請參閱[設定指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-hbase-setting-up-metrics.html)。

------
#### [ Using the console ]

若要從主控台使用 Amazon CloudWatch 代理程式建立叢集，請執行下列步驟：

**從主控台使用 CloudWatch 代理程式建立叢集**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/emr](https://console.aws.amazon.com/emr) 開啟 Amazon EMR 主控台。

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

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

1. 在**應用程式套件**下，選取您要安裝到叢集的 HBase 和其他應用程式，並在您的選擇中包含 CloudWatch 代理程式。

1. 展開**軟體設定**。接著，您可以使用 JSON 或陰影文字中示範的速記語法，直接在主控台中輸入組態。否則，您可以使用 JSON `Configurations` 物件來提供檔案的 Amazon S3 URI。如需指標的 JSON 範例組態詳細資訊，請參閱[設定指標](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-hbase-setting-up-metrics.html)。

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



------

# 設定指標
<a name="emr-hbase-setting-up-metrics"></a>

若要監控 HBase Master，您可以設定 Amazon CloudWatch Agent 來收集特定指標。

1. **設定 HBase Master 指標** – 若要監控 HBase Master，您可以設定 Amazon CloudWatch Agent 來收集特定指標。以下是追蹤主要指派管理員活動的組態範例：

   ```
   [
     {
       "Classification": "emr-metrics",
       "Properties": {},
       "Configurations": [
         {
           "Classification": "emr-hbase-master-metrics",
           "Properties": {
             "Hadoop:service=HBase,name=Master,sub=AssignmentManager": "AssignFailedCount,AssignSubmittedCount",
             "otel.metric.export.interval": "30000"
           },
           "Configurations": []
         }
       ]
     }
   ]
   ```

   在此設定中：
   + 我們會指定 MBean (`Hadoop:service=HBase,name=Master,sub=AssignmentManager`) 來收集 `AssignFailedCount`和 等指標`AssignSubmittedCount`。
   + 我們將間隔設定為每 30 秒 (30000 毫秒） 收集這些指標。

1. **設定 HBase 區域伺服器指標** – 若要監控 HBase 區域伺服器，請設定 CloudWatch 代理程式，如下所示：

   ```
   [
     {
       "Classification": "emr-metrics",
       "Properties": {},
       "Configurations": [
         {
           "Classification": "emr-hbase-region-server-metrics",
           "Properties": {
             "Hadoop:service=HBase,name=RegionServer,sub=IPC": "numActiveHandler,numActivePriorityHandler",
             "otel.metric.export.interval": "30000"
           },
           "Configurations": []
         }
       ]
     }
   ]
   ```

   此組態：
   + 監控區域伺服器上的作用中處理常式 (`numActiveHandler`、`numActivePriorityHandler`)。
   + 使用 30 秒的間隔進行指標收集。

1. **設定 HBase REST 伺服器指標** – 若要監控 HBase REST 介面，您可以使用下列組態：

   ```
   [
     {
       "Classification": "emr-metrics",
       "Properties": {},
       "Configurations": [
         {
           "Classification": "emr-hbase-rest-server-metrics",
           "Properties": {
             "Hadoop:service=HBase,name=REST": "successfulPut,successfulScanCount",
             "otel.metric.export.interval": "30000"
           },
           "Configurations": []
         }
       ]
     }
   ]
   ```

   在此範例中，CloudWatch Agent 會收集有關成功 PUT 操作的指標，並每 30 秒掃描計數。

1. **設定 HBase Thrift 伺服器指標** – 若要監控 HBase Thrift 伺服器，您可以使用如下所示的組態來設定指標：

   ```
   [
     {
       "Classification": "emr-metrics",
       "Properties": {},
       "Configurations": [
         {
           "Classification": "emr-hbase-thrift-server-metrics",
           "Properties": {
             "Hadoop:service=HBase,name=Thrift,sub=ThriftOne": "BatchGet_max,BatchGet_mean",
             "otel.metric.export.interval": "30000"
           },
           "Configurations": []
         }
       ]
     }
   ]
   ```

   此設定會追蹤 Thrift 伺服器上批次 GET 操作的最長和平均時間。

# 使用指標目的地
<a name="emr-hbase-using-metrics"></a>

透過 EMR 7.1，您可以選擇將指標資料傳送至 Amazon CloudWatch 或 Amazon Managed Service for Prometheus。此選項可讓您根據您的需求，無縫整合不同的監控工具。

## 將指標傳送至 Amazon CloudWatch
<a name="emr-hbase-using-metrics-cw"></a>

若要將指標傳送至 CloudWatch，請使用下列組態：

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

## 將指標傳送至 Amazon Managed Service for Prometheus
<a name="emr-hbase-using-metrics-prom"></a>

如果您偏好使用 Prometheus，請設定目的地並提供端點 URL：

```
[
  {
    "Classification": "emr-metrics",
    "Properties": {
      "metrics_destination": "prometheus",
      "prometheus_endpoint": "https://aps-workspaces.region.amazonaws.com/workspaces/workspace_id/api/v1/remote_write"
    },
    "Configurations": []
  }
]
```

將 取代`region`為您的 AWS 區域，並將 `workspace_id`取代為您的 Prometheus 工作區 ID。此組態會使用指定的端點，將您的 HBase 指標導向 Prometheus。

透過上述設定，您可以在**監控**索引標籤下查看下列指標。