

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

# 使用 Amazon CloudWatch 指標監控 AWS Glue
<a name="monitoring-awsglue-with-cloudwatch-metrics"></a>

您可以使用 AWS Glue 任務分析器來分析及監控 AWS Glue 操作。它會收集來自 AWS Glue 任務的原始資料，將這些資料處理成可讀取且幾近即時的指標並存放於 Amazon CloudWatch。系統會將這些統計資料保留於 CloudWatch 中並加以彙整，以便您存取歷史資訊，讓您更深入掌握應用程式的執行情況。

**注意**  
 啟用任務指標並建立 CloudWatch 自訂指標時，您可能會產生額外費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

## AWS Glue 指標概觀
<a name="metrics-overview"></a>

當您與 AWS Glue 互動時，它會傳送指標至 CloudWatch。您可使用 AWS Glue 主控台 (偏好的方法)、CloudWatch 主控台儀表板或 AWS Command Line Interface (AWS CLI) 中檢視這些指標。

**使用 AWS Glue 主控台儀表板檢視指標**

您能檢視任務指標的摘要或詳細圖表，或是任務執行的詳細圖表。

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

1. 在導覽窗格中，選擇**任務執行監控**。

1. 在**任務執行**中，選擇**動作**以停止目前正在執行的任務、檢視任務或倒轉任務書籤。

1. 選取任務，然後選擇**檢視執行詳細資訊**，以檢視有關任務執行的其他資訊。

**使用 CloudWatch 主控台儀表板檢視指標**

指標會先依服務命名空間分組，再依各命名空間內不同的維度組合分類。

1. 在 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**指標**。

1. 選擇 **Glue (Glue)** 命名空間。

**使用 檢視指標 AWS CLI**
+ 在命令提示中，使用下列命令。

  ```
  1. aws cloudwatch list-metrics --namespace Glue
  ```

AWS Glue 每 30 秒就會向 CloudWatch 回報指標，且 CloudWatch 指標儀表板也設定成每分鐘顯示一次指標。AWS Glue 指標表示先前回報數值中的差異值。適當時，指標儀表板將會彙總 (加總) 30 秒的值，以取得最後完整一分鐘的值。

### AWS Glue Spark 任務的指標行為
<a name="metrics-overview-spark"></a>

 當指令碼中的 `GlueContext` 進行初始化時，系統便已啟用 AWS Glue 指標。通常，唯有在 Apache Spark 任務快結束時，系統才會更新指標。這些指標代表目前所有完成的 Spark 任務彙總值。

但是，AWS Glue 傳遞至 CloudWatch 的 Spark 指標通常是絕對值，可代表這些指標在回報時的目前狀態。AWS Glue 每 30 秒就會向 CloudWatch 回報這些指標，且指標儀表板通常會顯示過去 1 分鐘內收到的資料點平均值。

AWS Glue 指標名稱皆有以下其中一個類型的前綴：
+ `glue.driver.` – 若是以此字首為名稱開頭，即代表該指標屬於 Spark 驅動程式中所有執行器的彙總 AWS Glue 指標，或是對應至 Spark 驅動程式的 Spark 指標。
+ `glue.`*executorId*`.` – *executorId* 是特定 Spark 執行器的數量。它對應至日誌中的執行器。
+ `glue.ALL.` – 名稱開頭為此字首的指標即是所有 Spark 執行器的彙總值。

## AWS Glue 指標
<a name="awsglue-metrics"></a>

AWS Glue 設定檔，並每 30 秒將下列指標傳送至 CloudWatch，指標 AWS Glue 儀表板每分鐘報告一次：


| 指標 | Description | 
| --- | --- | 
|  `glue.driver.aggregate.bytesRead` |  由所有執行器中執行的所有已完成 Spark 任務，從所有資料來源讀取的位元組數。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：位元組 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 此指標的使用方式與 `glue.ALL.s3.filesystem.read_bytes` 指標相同，差別在於此指標會在 Spark 任務結束時更新並擷取非 S3 資料來源。  | 
|  `glue.driver.aggregate.elapsedTime` |  ETL 經過時間 (以毫秒為單位) (不包括任務啟動程序時間)。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：毫秒 可用於判斷任務執行平均所需的時間。 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.aggregate.numCompletedStages` |  任務中已完成階段的數量。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.numCompletedTasks` |  任務中已完成任務的數目。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.numFailedTasks` |  失敗的任務數量。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 這些資料可用來設定警示，以防止增加失敗，這些失敗可能會提出資料、叢集或指令碼的異常情況。  | 
|  `glue.driver.aggregate.numKilledTasks` |  終止的任務數量。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.recordsRead` |  由所有執行器中執行的所有已完成 Spark 任務，從所有資料來源讀取的記錄數。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 此指標的使用方式類似於 `glue.ALL.s3.filesystem.read_bytes` 指標，差別在於此指標會在 Spark 任務結束時更新。  | 
|   `glue.driver.aggregate.shuffleBytesWritten` |  自上一個報告以來，所有執行器寫入隨機播放資料的位元組數 （由 AWS Glue 指標儀表板彙總為上一分鐘為此目的寫入的位元組數）。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：位元組 可用於監視：任務中的資料隨機播放 (大型聯結、GroupBy、重新分割、聯合)。 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.aggregate.shuffleLocalBytesRead` |  自上一個報告以來，所有執行器讀取以在它們之間隨機播放資料的位元組數 （由 AWS Glue 指標儀表板彙總為上一分鐘為此目的讀取的位元組數）。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 單位：位元組 可用於監視：任務中的資料隨機播放 (大型聯結、GroupBy、重新分割、聯合)。 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.BlockManager.disk.diskSpaceUsed_MB` |  在所有執行器中使用的 MB 磁碟空間數目。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：平均。這是 Spark 指標，報告為絕對值。 單位：MB 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.ExecutorAllocationManager.executors.numberAllExecutors` |  目前正在執行中任務執行器的數量。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：平均。這是 Spark 指標，報告為絕對值。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.ExecutorAllocationManager.executors.numberMaxNeededExecutors` |  滿足目前負載所需的最大值 (主動執行中和擱置中) 任務執行器數目。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：上限。這是 Spark 指標，報告為絕對值。 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.jvm.heap.usage`  `glue.`*executorId*`.jvm.heap.usage`  `glue.ALL.jvm.heap.usage`  |  此驅動程式之 JVM 堆疊所使用的記憶體佔比 (比例：0-1)、由 executorId 所辨識的執行器，或所有執行器。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：平均。這是 Spark 指標，報告為絕對值。 單位：百分比 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.jvm.heap.used`  `glue.`*executorId*`.jvm.heap.used`  `glue.ALL.jvm.heap.used`  |  JVM 堆積針對驅動程式、由 *executorId* 識別的執行器或所有執行器，所使用的記憶體位元組數目。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：平均。這是 Spark 指標，報告為絕對值。 單位：位元組 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.s3.filesystem.read_bytes`  `glue.`*executorId*`.s3.filesystem.read_bytes`  `glue.ALL.s3.filesystem.read_bytes`  |  自上次報告以來，驅動程式、*executorId* 識別的執行器或 ALL 執行器從 Amazon S3 讀取的位元組數 （由 AWS Glue 指標儀表板彙總為上一分鐘讀取的位元組數）。 有效維度：`JobName`、`JobRunId` 以及 `Type` (計量)。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 AWS Glue 指標儀表板曲線下的區域可用來視覺化比較兩個不同任務執行讀取的位元組。 單位：位元組。 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 產生的資料可用於： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.s3.filesystem.write_bytes`  `glue.`*executorId*`.s3.filesystem.write_bytes`  `glue.ALL.s3.filesystem.write_bytes`  |  自上次報告以來，驅動程式、*executorId* 識別的執行器或 ALL 執行器寫入 Amazon S3 的位元組數 （由 AWS Glue 指標儀表板彙總為前一分鐘內寫入的位元組數）。 有效維度：`JobName`、`JobRunId` 以及 `Type` (計量)。 有效的統計數字：總和。此指標是來自上次報告值的差異值，因此在 AWS Glue 指標儀表板上，SUM 統計資料會用於彙總。 AWS Glue 指標儀表板曲線下的區域可用來視覺化比較兩個不同任務執行所寫入的位元組。 單位：位元組 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.streaming.numRecords` |  在微批次中接收的記錄數目。此指標僅適用於 2.0 版及更高 AWS Glue 版本的 AWS Glue 串流任務。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和、上限、下限、平均、百分位數 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.streaming.batchProcessingTimeInMs` |  處理批次所需的時間 (以毫秒為單位)。此指標僅適用於 2.0 版及更高 AWS Glue 版本的 AWS Glue 串流任務。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（計數）。 有效的統計數字：總和、上限、下限、平均、百分位數 單位：計數 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.system.cpuSystemLoad`  `glue.`*executorId*`.system.cpuSystemLoad`  `glue.ALL.system.cpuSystemLoad`  |  驅動程式使用的 CPU 系統負載佔比 (比例：0-1)、由 *executorId* 所辨識的執行器，或所有執行器。 有效維度： `JobName`( AWS Glue 任務的名稱）、 `JobRunId`(JobRun ID 或 `ALL`) 和 `Type`（規格）。 有效的統計數字：平均。此指標會報告為絕對值。 單位：百分比 可用於監控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 使用資料的一些方法： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 

## AWS Glue 指標的維度
<a name="awsglue-metricdimensions"></a>

AWS Glue 指標使用 AWS Glue 命名空間，並提供下列維度的指標：


| 維度 | Description | 
| --- | --- | 
|  `JobName`  |  此維度會篩選特定任務之所有 AWS Glue 任務執行的指標。  | 
|  `JobRunId`  |  此維度會依 JobRun ID 或 篩選特定 AWS Glue 任務執行的指標`ALL`。  | 
|  `Type`  |  此維度會依 `count` (彙總數字) 或 `gauge` (某個時間點的值) 篩選指標。  | 

如需更多資訊，請參閱 [Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/)。