

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

# CloudWatch 中的 Apache Airflow 環境指標
<a name="access-metrics-cw"></a>

Apache Airflow v2 和 v3 已設定為收集 [StatsD](https://github.com/etsy/statsd) 指標，並將 Amazon Managed Workflows for Apache Airflow 環境的 StatsD 指標傳送至 Amazon CloudWatch。Apache Airflow 傳送的指標完整清單可在 *Apache Airflow 參考指南*中的[指標](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/metrics.html)頁面上取得。此頁面說明 CloudWatch 中可用的 Apache Airflow 指標，以及如何在 CloudWatch 主控台中存取指標。

**Contents**
+ [條款](#access-metrics-cw-terms)
+ [維度](#metrics-dimensions)
+ [在 CloudWatch 主控台中存取指標](#access-metrics-cw-console)
+ [CloudWatch 中可用的 Apache Airflow 指標](#available-metrics-cw)
  + [Apache Airflow 計數器](#counters-metrics)
  + [Apache Airflow 量測器](#gauges-metrics)
  + [Apache Airflow 計時器](#timers-metrics)
+ [選擇報告哪些指標](#choosing-metrics)
+ [後續步驟？](#mwaa-metrics202-next-up)

## 條款
<a name="access-metrics-cw-terms"></a>

**命名空間**  
命名空間是 AWS 服務的 CloudWatch 指標的容器。對於 Amazon MWAA，命名空間為 *AmazonMWAA*。

**CloudWatch 指標**  
CloudWatch 指標代表 CloudWatch 特有的一組按時間順序排列的資料點。

**Apache Airflow 指標**  
Apache Airflow 特定的[指標](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/metrics.html )。

**維度**  
維度是一組名稱值對，是指標身分的一部分。

**單位**  
統計資料具有度量單位。對於 Amazon MWAA，單位包括*計數*、*秒*和*毫秒*。對於 Amazon MWAA，單位是根據原始 Airflow 指標中的單位設定。

## 維度
<a name="metrics-dimensions"></a>

本節說明 CloudWatch 中 Apache Airflow 指標的 CloudWatch *Dimensions* 分組。


| 維度 | Description | 
| --- | --- | 
| DAG | 指出特定的 Apache Airflow DAG 名稱。 | 
| DAG 檔案名稱 | 指出特定的 Apache Airflow DAG 檔案名稱。 | 
| 函式 | 此維度用於改善 CloudWatch 中指標的分組。 | 
| 任務 | 指出排程器執行的 Apache Airflow 任務。值一律為 `Job`。 | 
| 運算子 | 指出特定的 Apache Airflow 運算子。 | 
| 集區 | 指出特定的 Apache Airflow 工作者集區。 | 
| 任務 | 指出特定的 Apache Airflow 任務。 | 
| HostName | 指出特定執行中 Apache Airflow 程序的主機名稱。 | 

## 在 CloudWatch 主控台中存取指標
<a name="access-metrics-cw-console"></a>

本節說明如何存取 CloudWatch 中特定 DAG 的效能指標。

**存取維度的效能指標**

1. 在 CloudWatch 主控台上開啟[指標頁面](https://console.aws.amazon.com/cloudwatch/home#metricsV2:graph=~())。

1. 選取您的 AWS 區域。

1. 選擇 **AmazonMWAA** 命名空間。

1. **在所有指標**索引標籤中，選取維度。例如 *DAG、Environment*。

1. 選擇維度的 CloudWatch 指標。例如，*TaskInstanceSuccesses* 或 *TaskInstanceDuration*。選擇繪製**所有搜尋結果的圖形**。

1. 選擇**圖形化指標**索引標籤，以存取 Apache Airflow 指標的效能統計資料，例如 *DAG、環境、任務*。

## CloudWatch 中可用的 Apache Airflow 指標
<a name="available-metrics-cw"></a>

本節說明傳送至 CloudWatch 的 Apache Airflow 指標和維度。

### Apache Airflow 計數器
<a name="counters-metrics"></a>

本節中的 Apache Airflow 指標包含有關 [Apache Airflow *計數器*](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/metrics.html#counters)的資料。


| CloudWatch 指標 | Apache Airflow 指標 | 單位 | 維度 | 
| --- | --- | --- | --- | 
| SLAMissed 僅適用於 Apache Airflow v2.4.3 至 v2.10.3。  | sla\_missed | 計數 | 函數、排程器 | 
| FailedSLACallback 僅適用於 Apache Airflow v2.4.3 至 v2.10.3。  | sla\_callback\_notification\_failure | 計數 | 函數、排程器 | 
| 更新 適用於 Apache Airflow 2.6.3 版及更新版本。  | dataset.updates | 計數 | 函數、排程器 | 
| 孤立 適用於 Apache Airflow 2.6.3 版及更新版本。  | dataset.orphaned | 計數 | 函數、排程器 | 
| FailedCeleryTaskExecution 適用於 Apache Airflow 2.4.3 版及更新版本。  | celery.execute\_command.failure | 計數 | 函數、Celery | 
| FilePathQueueUpdateCount 適用於 Apache Airflow 2.6.3 版及更新版本。  | dag\_processing.file\_path\_queue\_update\_count | 計數 | 函數、排程器 | 
| CriticalSectionBusy | scheduler.critical\_section\_busy | 計數 | 函數、排程器 | 
| DagBagSize | dagbag\_size | 計數 | 函數、DAG 處理 | 
| DagCallbackExceptions | dag.callback\_exceptions | 計數 | DAG，全部 | 
| FailedSLAEmailAttempts 不適用於 Apache Airflow v3.0.6 和更新版本。  | sla\_email\_notification\_failure | 計數 | 函數、排程器 | 
| TaskInstanceFinished | ti.finish.{dag\_id}.{task\_id}.{state} | 計數 | DAG、{dag\_id}<br />任務，{task\_id}<br />狀態，{state} | 
| JobEnd | {job\_name}\_end | 計數 | 任務，{job\_name} | 
| JobHeartbeatFailure | {job\_name}\_heartbeat\_failure | 計數 | 任務，{job\_name} | 
| JobStart | {job\_name}\_start | 計數 | 任務，{job\_name} | 
| ManagerStalls | dag\_processing.manager\_stalls | 計數 | 函數、DAG 處理 | 
| OperatorFailures | Operator\_failures\_{operator\_name} | 計數 | 運算子，{operator\_name} | 
| OperatorSuccesses | Operator\_successes\_{operator\_name} | 計數 | 運算子，{operator\_name} | 
| OtherCallbackCount Apache Airflow 2.6.3 版及更新版本中提供。  | dag\_processing.other\_callback\_count | 計數 | 函數、排程器 | 
| Processes | dag\_processing.processes | 計數 | 函數、DAG 處理 | 
| SchedulerHeartbeat | scheduler\_heartbeat | 計數 | 函數、排程器 | 
| StartedTaskInstances | ti.start.{dag\_id}.{task\_id} | 計數 | DAG，全部<br />任務，全部 | 
| SlaCallbackCount | dag\_processing.sla\_callback\_count 適用於 Apache Airflow 2.6.3 版及更新版本。  | 計數 | 函數、排程器 | 
| TasksKilledExternally | scheduler.tasks.killed\_externally | 計數 | 函數、排程器 | 
| TaskTimeoutError | celery.task\_timeout\_error | 計數 | 函數、Celery | 
| TaskInstanceCreatedUsingOperator | task\_instance\_created-{operator\_name} | 計數 | 運算子，{operator\_name} | 
| TaskInstancePreviouslySucceeded | previously\_succeeded | 計數 | DAG，全部<br />任務，全部 | 
| TaskInstanceFailures | ti\_failures | 計數 | DAG，全部<br />任務，全部 | 
| TaskInstanceSuccesses | ti\_successes | 計數 | DAG，全部<br />任務，全部 | 
| TaskRemovedFromDAG | task\_removed\_from\_dag.{dag\_id} | 計數 | DAG、{dag\_id} | 
| TaskRestoredToDAG | task\_restored\_to\_dag.{dag\_id} | 計數 | DAG、{dag\_id} | 
| TriggersSucceeded 適用於 Apache Airflow 2.7.2 版及更新版本。  | triggers.succeeded | 計數 | 函數、觸發 | 
| TriggersFailed 適用於 Apache Airflow 2.7.2 版及更新版本。  | triggers.failed | 計數 | 函數、觸發 | 
| TriggersBlockedMainThread 適用於 Apache Airflow 2.7.2 版及更新版本。  | triggers.blocked\_main\_thread | 計數 | 函數、觸發 | 
| TriggerHeartbeat 適用於 Apache Airflow 2.8.1 版及更新版本。  | triggerer\_heartbeat | 計數 | 函數、觸發器 | 
| TaskInstanceCreatedUsingOperator | airflow.task\_instance\_created\_`{operator_name}` 適用於 Apache Airflow 2.7.2 版及更新版本。  | 計數 | 運算子、 `{operator_name}` | 
| ZombiesKilled | zombies\_killed | 計數 | DAG，全部<br />任務，全部 | 

### Apache Airflow 量測器
<a name="gauges-metrics"></a>

本節中的 Apache Airflow 指標包含有關 [Apache Airflow *量測計*](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/metrics.html#gauges)的資料。


| CloudWatch 指標 | Apache Airflow 指標 | 單位 | 維度 | 
| --- | --- | --- | --- | 
| DAGFileRefreshError | dag\_file\_refresh\_error | 計數 | 函數、DAG 處理 | 
| ImportErrors | dag\_processing.import\_errors | 計數 | 函數、DAG 處理 | 
| ExceptionFailures | smart\_sensor\_operator.exception\_failures | 計數 | 函數、智慧型感應器運算子 | 
| ExecutedTasks | smart\_sensor\_operator.executed\_tasks | 計數 | 函數、智慧型感應器運算子 | 
| InfraFailures | smart\_sensor\_operator.infra\_failures | 計數 | 函數、智慧型感應器運算子 | 
| LoadedTasks | smart\_sensor\_operator.loaded\_tasks | 計數 | 函數、智慧型感應器運算子 | 
| TotalParseTime | dag\_processing.total\_parse\_time | 秒鐘 | 函數、DAG 處理 | 
| TriggeredDagRuns Apache Airflow 2.6.3 版及更新版本中提供。  | dataset.triggered\_dagruns | 計數 | 函數、排程器 | 
| TriggersRunning Apache Airflow 2.7.2 版及更新版本中提供。  | triggers.running.{{{hostname}}} | 計數 | 函數、觸發<br />HostName、{{{hostname}}} | 
| PoolDeferredSlots Apache Airflow 2.7.2 版及更新版本中提供。  | pool.deferred\_slots。`{pool_name}` | 計數 | 集區，{pool\_name} | 
| DAGFileProcessingLastRunSecondsAgo | dag\_processing.last\_run.seconds\_ago.{dag\_filename} | 秒鐘 | DAG 檔案名稱，{dag\_filename} | 
| OpenSlots | executor.open\_slots | 計數 | 函數、執行器 | 
| OrphanedTasksAdopted | scheduler.orphaned\_tasks.adopted | 計數 | 函數、排程器 | 
| OrphanedTasksCleared | scheduler.orphaned\_tasks.cleared | 計數 | 函數、排程器 | 
| PokedExceptions | smart\_sensor\_operator.poked\_exception | 計數 | 函數、智慧型感應器運算子 | 
| PokedSuccess | smart\_sensor\_operator.poked\_success | 計數 | 函數、智慧型感應器運算子 | 
| PokedTasks | smart\_sensor\_operator.poked\_tasks | 計數 | 函數、智慧型感應器運算子 | 
| PoolFailures | pool.open\_slots.{pool\_name} | 計數 | 集區，{pool\_name} | 
| PoolStarvingTasks | pool.starving\_tasks.{pool\_name} | 計數 | 集區，{pool\_name} | 
| PoolOpenSlots | pool.open\_slots.{pool\_name} | 計數 | 集區，{pool\_name} | 
| PoolQueuedSlots | pool.queued\_slots.{pool\_name} | 計數 | 集區，{pool\_name} | 
| PoolRunningSlots | pool.running\_slots.{pool\_name} | 計數 | 集區，{pool\_name} | 
| ProcessorTimeouts | dag\_processing.processor\_timeouts | 計數 | 函數、DAG 處理 | 
| QueuedTasks | executor.queued\_tasks | 計數 | 函數、執行器 | 
| RunningTasks | executor.running\_tasks | 計數 | 函數、執行器 | 
| TasksExecutable | scheduler.tasks.executable | 計數 | 函數、排程器 | 
| TasksPending 不適用於 Apache Airflow v2.2 和更新版本。  | scheduler.tasks.pending | 計數 | 函數、排程器 | 
| TasksRunning | scheduler.tasks.running | 計數 | 函數、排程器 | 
| TasksStarving | scheduler.tasks.starving | 計數 | 函數、排程器 | 
| TasksWithoutDagRun | scheduler.tasks.without\_dagrun | 計數 | 函數、排程器 | 
| DAGFileProcessingLastNumOfDbQueries 適用於 Apache Airflow 2.10.1 版及更新版本。  | dag\_processing.last\_num\_of\_db\_queries.{dag\_filename} | 計數 | DAG 檔案名稱，{dag\_filename} | 
| PoolScheduledSlots 適用於 Apache Airflow 2.10.1 版及更新版本。  | pool.scheduled\_slots.{pool\_name} | 計數 | 集區，{pool\_name} | 
| TaskCpuUsage Apache Airflow 2.10.1 版及更新版本中提供。  | cpu.usage.{dag\_id}.{task\_id} | 百分比 | DAG、{dag\_id}<br />任務，{task\_id} | 
| TaskMemoryUsage Apache Airflow 2.10.1 版及更新版本中提供。  | mem.usage.{dag\_id}.{task\_id} | 百分比 | DAG、{dag\_id}<br />任務，{task\_id} | 

### Apache Airflow 計時器
<a name="timers-metrics"></a>

本節中的 Apache Airflow 指標包含有關 [Apache Airflow *計時器*](https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/metrics.html#timers)的資料。


| CloudWatch 指標 | Apache Airflow 指標 | 單位 | 維度 | 
| --- | --- | --- | --- | 
| CollectDBDags | collect\_db\_dags | 毫秒 | 函數、DAG 處理 | 
| CriticalSectionDuration | scheduler.critical\_section\_duration | 毫秒 | 函數、排程器 | 
| CriticalSectionQueryDuration 適用於 Apache Airflow 2.5.1 版及更新版本。  | scheduler.critical\_section\_query\_duration | 毫秒 | 函數、排程器 | 
| DAGDependencyCheck | dagrun.dependency-check.{dag\_id} | 毫秒 | DAG、{dag\_id} | 
| DAGDurationFailed | dagrun.duration.failed.{dag\_id} | 毫秒 | DAG、{dag\_id} | 
| DAGDurationSuccess | dagrun.duration.success.{dag\_id} | 毫秒 | DAG、{dag\_id} | 
| DAGFileProcessingLastDuration | dag\_processing.last\_duration.{dag\_filename} | 秒鐘 | DAG 檔案名稱，{dag\_filename} | 
| DAGScheduleDelay | dagrun.schedule\_delay.{dag\_id} | 毫秒 | DAG、{dag\_id} | 
| FirstTaskSchedulingDelay | dagrun.{dag\_id}.first\_task\_scheduling\_delay | 毫秒 | DAG、{dag\_id} | 
| SchedulerLoopDuration 適用於 Apache Airflow 2.5.1 版及更新版本。  | scheduler.scheduler\_loop\_duration | 毫秒 | 函數、排程器 | 
| TaskInstanceDuration | dag.{dag\_id}.{task\_id}.duration | 毫秒 | DAG、{dag\_id}<br />任務，{task\_id} | 
| TaskInstanceQueuedDuration | dag.`{dag_id}`.`{task_id}`queued\_duration 適用於 Apache Airflow 2.7.2 版及更新版本。  | 毫秒 | DAG、{dag\_id}<br />任務，{task\_id} | 
| TaskInstanceScheduledDuration 適用於 Apache Airflow 2.7.2 版及更新版本。  | dag.`{dag_id}``{task_id}`.scheduled\_duration | 毫秒 | DAG、{dag\_id}<br />任務，{task\_id} | 

## 選擇報告哪些指標
<a name="choosing-metrics"></a>

您可以使用下列 Amazon MWAA [組態選項](configuring-env-variables.md)，選擇向 CloudWatch 發出或由 Apache Airflow 封鎖的 Apache Airflow 指標：
+ **`metrics.metrics_allow_list`** — 逗號分隔的字首清單，可用來選取環境向 CloudWatch 發出的指標。如果您希望 Apache Airflow 不傳送所有可用的指標，而是選取元素子集，請使用此選項。例如 `scheduler,executor,dagrun`。
+ **`metrics.metrics_block_list`** — 逗號分隔字首清單，用於篩選以清單元素開頭的指標。例如 `scheduler,executor,dagrun`。

如果您同時設定 `metrics.metrics_allow_list`和 `metrics.metrics_block_list`，Apache Airflow 會忽略 `metrics.metrics_block_list`。如果您設定 `metrics.metrics_block_list` 但未設定 `metrics.metrics_allow_list`，Apache Airflow 會篩選掉您在 中指定的元素`metrics.metrics_block_list`。

**注意**  
`metrics.metrics_allow_list` 和 `metrics.metrics_block_list`組態選項僅適用於 Apache Airflow v2.6.3 和更新版本。對於舊版 Apache Airflow，請`metrics.statsd_block_list`改用 `metrics.statsd_allow_list`和 。

## 後續步驟？
<a name="mwaa-metrics202-next-up"></a>
+ 探索用於在 [PublishMetrics](https://docs.aws.amazon.com/mwaa/latest/API/API_PublishMetrics.html) 發佈環境運作狀態指標的 Amazon MWAA API 操作。