

# 使用 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 管理控制台，然后打开 AWS Glue 控制台，网址为：[https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue/)。

1. 在导航窗格中，选择**作业运行监控**。

1. 在**作业运行**中，选择**操作**以停止当前正在运行的作业、查看作业或倒回作业书签。

1. 选择一个作业，然后选择**查看运行详细信息**以查看有关该作业运行的其他信息。

**使用 CloudWatch 控制台控制面板查看指标**

指标的分组首先依据服务命名空间，然后依据每个命名空间内的各种维度组合。

1. 访问 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 打开 CloudWatch 控制台。

1. 在导航窗格中，选择**指标**。

1. 选择 **Glue** 命名空间。

**使用 AWS CLI 查看指标**
+ 在命令提示符处，使用以下命令。

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

AWS Glue 每隔 30 秒向 CloudWatch 报告一次指标，CloudWatch 指标控制面板配置为每分钟显示一次指标。AWS Glue 指标表示先前报告的值的增量值。在适当时，指标控制面板会聚合（合计）30 秒值以获取整个最后一分钟的值。

### Spark 作业的 AWS Glue 指标行为
<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 指标控制面板每分钟报告一次：


| 指标 | 说明 | 
| --- | --- | 
|  `glue.driver.aggregate.bytesRead` |  所有执行程序中运行的所有已完成的 Spark 任务从所有数据源读取的字节数。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：字节 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：毫秒 可用于确定任务运行的平均时长。 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.aggregate.numCompletedStages` |  任务中已完成的阶段数量。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.numCompletedTasks` |  任务中已完成的任务数量。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.numFailedTasks` |  失败的任务数。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 这些数据可用于为增加的故障设置警报，这些故障可能表明数据、集群或脚本出现异常。  | 
|  `glue.driver.aggregate.numKilledTasks` |  已终止的任务数量。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.aggregate.recordsRead` |  所有执行程序中运行的所有已完成的 Spark 任务从所有数据源读取的记录数。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：字节 可用于监控：任务（大型联接、分组依据、重新分区、合并）中的数据随机排序。 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|   `glue.driver.aggregate.shuffleLocalBytesRead` |  自上次报告以来所有执行程序为在它们之间对数据进行随机排序而读取的字节数（由 AWS Glue 指标控制面板聚合为前一分钟内为此目的读取的字节数）。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。 单位：字节 可用于监控：任务（大型联接、分组依据、重新分区、合并）中的数据随机排序。 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.BlockManager.disk.diskSpaceUsed_MB` |  所有执行程序中所用磁盘空间的兆字节数。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（量规）。 有效统计数据：平均值。这是 Spark 指标，报告为绝对值。 单位：兆字节 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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* 标识的执行程序、所有执行程序从 Amazon S3 读取的字节数（由 AWS Glue 指标控制面板聚合为上一分钟内读取的字节数）。 有效维度：`JobName`、`JobRunId` 和 `Type`（量规）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。AWS Glue 指标控制面板上曲线下面的区域可用于直观比较两个不同任务运行读取的字节。 单位：字节。 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 生成的数据可用于： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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* 标识的执行程序、所有执行程序从 Amazon S3 写入的字节数（由 AWS Glue 指标控制面板聚合为上一分钟内写入的字节数）。 有效维度：`JobName`、`JobRunId` 和 `Type`（量规）。 有效统计数据：SUM 此指标是上次报告值的增量值，因此，在 AWS Glue 指标控制面板上，SUM 统计数据用于聚合。AWS Glue 指标控制面板上曲线下面的区域可用于直观比较两个不同任务运行写入的字节。 单位：字节 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.streaming.numRecords` |  微批处理中接收的记录数。此指标仅适用于 AWS Glue 流式传输任务（采用 AWS Glue 2.0 版及更高版本）。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：总计、最大值、最小值、平均值、百分比 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 
|  `glue.driver.streaming.batchProcessingTimeInMs` |  处理批处理所需的时间（以毫秒为单位）。此指标仅适用于 AWS Glue 流式传输任务（采用 AWS Glue 2.0 版及更高版本）。 有效维度：`JobName`（AWS Glue 任务的名称）、`JobRunId`（JobRun ID 或 `ALL`）和 `Type`（计数）。 有效统计数据：总计、最大值、最小值、平均值、百分比 单位：个 可用于监控： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html) 数据的一些使用方式： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/monitoring-awsglue-with-cloudwatch-metrics.html)  | 

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

AWS Glue 指标使用 AWS Glue 命名空间并提供以下维度的指标。


| 维度 | 说明 | 
| --- | --- | 
|  `JobName`  |  此维度筛选特定 AWS Glue 任务的所有任务运行的指标。  | 
|  `JobRunId`  |  此维度按 JobRun ID 或 `ALL` 筛选特定 AWS Glue 任务的所有任务运行的指标。  | 
|  `Type`  |  此维度按 `count`（总数）或 `gauge`（在某个时间点的值）筛选指标。  | 

有关更多信息，请参阅《[Amazon CloudWatch 用户指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/)》。