

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

# 監控 CloudWatch 中的 S3 Storage Lens 指標
<a name="storage_lens_view_metrics_cloudwatch"></a>

您可以將 S3 Storage Lens 指標發佈到 Amazon CloudWatch，以在 [CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)中建立統一的運作狀態檢視。您也可以使用 CloudWatch 功能 (例如警示和觸發動作、指標數學和異常偵測) 來監控 S3 Storage Lens 指標並對其採取動作。此外，CloudWatch API 操作可讓應用程式 (包括第三方供應商) 存取您的 S3 Storage Lens 指標。如需有關 CloudWatch 功能的詳細資訊，請參閱《[Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html)》。

您可以使用 Amazon S3 主控台 AWS CLI、Amazon S3 REST API 和 AWS SDKs，為新的或現有的儀表板組態啟用 CloudWatch 發佈選項。升級至 S3 Storage Lens 進階指標和建議儀表板可以使用 CloudWatch 發佈選項。如需 S3 Storage Lens 進階指標和建議定價，請參閱 [Amazon S3 定價](https://aws.amazon.com/s3/pricing/)。不會產生額外的 CloudWatch 指標發佈費用；不過，儀表板、警示和 API 呼叫等其他 CloudWatch 費用則適用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

S3 Storage Lens 指標會在擁有 S3 Storage Lens 組態的帳戶中發佈至 CloudWatch。在進階指標中啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中依組態 ID、帳戶、儲存貯體 （僅適用於儲存貯體層級指標）、區域和儲存類別存取帳戶層級和儲存貯體層級指標。在 CloudWatch 中不提供字首層級的指標。

**注意**  
S3 Storage Lens 指標是每日指標，每天向 CloudWatch 發佈一次。在 CloudWatch 中查詢 S3 Storage Lens 指標時，查詢的時段必須為 1 天 (86400 秒)。在每日 S3 Storage Lens 指標出現在 Amazon S3 主控台的 S3 Storage Lens 儀表板中之後，這些相同指標可能會需要幾個小時才會出現在 CloudWatch 中。首次啟用 S3 Storage Lens 指標的 CloudWatch 發佈選項時，您的指標最多可能需要 24 小時才能發佈到 CloudWatch。

啟用 CloudWatch 發佈選項後，您可以使用下列 CloudWatch 功能來監控和分析您的 S3 Storage Lens 資料：
+ [儀表板](storage-lens-cloudwatch-monitoring-cloudwatch.md#storage-lens-cloudwatch-monitoring-cloudwatch-dashboards) – 使用 CloudWatch 儀表板來建立自訂的 S3 Storage Lens 儀表板。將您的 CloudWatch 儀表板分享給無法直接存取您 AWS 帳戶、跨團隊、利益相關者以及組織外部人員的人員。
+ [警示和觸發的動作](storage-lens-cloudwatch-monitoring-cloudwatch.md#storage-lens-cloudwatch-monitoring-cloudwatch-alarms) – 設定警示，以監視指標，並在超出閾值時採取動作。例如，您可以設定警示，當 **Incomplete Multipart Upload Bytes** (未完成的分段上傳位元組) 指標連續三天超過 1 GB 時，傳送 Amazon SNS 通知。
+ [異常偵測](storage-lens-cloudwatch-monitoring-cloudwatch.md#storage-lens-cloudwatch-monitoring-cloudwatch-alarms) – 啟用異常偵測以持續分析指標、判斷正常基準以及顯露異常情況。您可以建立以指標預期值為基礎的異常偵測警示。例如，您可以監控 **Object Lock Enabled Bytes** (已啟用物件鎖定的位元組) 指標的異常情況，以偵測未經授權即移除物件鎖定設定的情況。
+ [指標數學](storage-lens-cloudwatch-monitoring-cloudwatch.md#storage-lens-cloudwatch-monitoring-cloudwatch-metric-math) – 您還可以使用指標數學，以查詢多個 S3 Storage Lens 指標，並使用數學表達式根據這些指標來建立新的時間序列。例如，您可以建立新指標，透過將 `StorageBytes` 除以 `ObjectCount` 來取得平均物件大小。

如需有關 S3 Storage Lens 指標之 CloudWatch 發佈選項的詳細資訊，請參閱下列主題。

**Topics**
+ [S3 Storage Lens 指標和維度](storage-lens-cloudwatch-metrics-dimensions.md)
+ [啟用 S3 Storage Lens 的 CloudWatch 發佈](storage-lens-cloudwatch-enable-publish-option.md)
+ [使用 CloudWatch 中的 S3 Storage Lens 指標](storage-lens-cloudwatch-monitoring-cloudwatch.md)

# S3 Storage Lens 指標和維度
<a name="storage-lens-cloudwatch-metrics-dimensions"></a>

若要將 S3 Storage Lens 指標傳送至 CloudWatch，您必須在 S3 Storage Lens 進階指標中啟用 CloudWatch 發佈選項。在啟用進階指標之後，您可以使用 [CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)來監控 S3 Storage Lens 指標與其他應用程式指標，並建立統一的運作狀態檢視。您可以使用維度，依組織、帳戶、儲存貯體、儲存類別、區域和指標組態 ID 在 CloudWatch 中篩選 S3 Storage Lens 指標。

S3 Storage Lens 指標會在擁有 S3 Storage Lens 組態的帳戶中發佈至 CloudWatch。在進階指標中啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中依組態 ID、帳戶、儲存貯體 （僅適用於儲存貯體層級指標）、區域和儲存類別存取帳戶層級和儲存貯體層級指標。在 CloudWatch 中不提供字首層級的指標。

**注意**  
S3 Storage Lens 指標是每日指標，每天向 CloudWatch 發佈一次。在 CloudWatch 中查詢 S3 Storage Lens 指標時，查詢的時段必須為 1 天 (86400 秒)。在每日 S3 Storage Lens 指標出現在 Amazon S3 主控台的 S3 Storage Lens 儀表板中之後，這些相同指標可能會需要幾個小時才會出現在 CloudWatch 中。首次啟用 S3 Storage Lens 指標的 CloudWatch 發佈選項時，您的指標最多可能需要 24 小時才能發佈到 CloudWatch。

如需有關 CloudWatch 中 S3 Storage Lens 指標和維度的詳細資訊，請參閱下列主題。

**Topics**
+ [指標](#storage-lens-cloudwatch-metrics)
+ [維度](#storage-lens-cloudwatch-dimensions)

## 指標
<a name="storage-lens-cloudwatch-metrics"></a>

S3 Storage Lens 指標會在 CloudWatch 中作為指標提供。S3 Storage Lens 指標會發佈至 `AWS/S3/Storage-Lens` 命名空間。此命名空間僅適用於 S3 Storage Lens 指標。Amazon S3 儲存貯體、請求和複寫指標會發佈至 `AWS/S3` 命名空間。

S3 Storage Lens 指標會在擁有 S3 Storage Lens 組態的帳戶中發佈至 CloudWatch。在進階指標中啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中依組態 ID、帳戶、儲存貯體 （僅適用於儲存貯體層級指標）、區域和儲存類別存取帳戶層級和儲存貯體層級指標。在 CloudWatch 中不提供字首層級的指標。

在 S3 Storage Lens 中，指標只會彙總並存放在指定的主要區域。S3 Storage Lens 指標也會發佈至您在 S3 Storage Lens 組態中指定主要區域中的 CloudWatch。

如需 S3 Storage Lens 指標的完整清單，包括 CloudWatch 中這些可用指標的清單，請參閱 [Amazon S3 Storage Lens 指標詞彙表](storage_lens_metrics_glossary.md)。

**注意**  
CloudWatch 中 S3 Storage Lens 指標的有效統計數字為平均值。如需 CloudWatch 中統計數字的詳細資訊，請參閱《Amazon CloudWatch 使用者指南**》中的 [CloudWatch 統計數字定義](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html)。

### CloudWatch 中的 S3 Storage Lens 指標資料精細程度
<a name="storage-lens-cloudwatch-metrics-granularity"></a>

S3 Storage Lens 提供組織、帳戶、儲存貯體和字首精細程度的指標。S3 Storage Lens 會將組織、帳戶和儲存貯體層級的 S3 Storage Lens 指標發佈至 CloudWatch。在 CloudWatch 中不提供字首層級的 S3 Storage Lens 指標。

如需 CloudWatch 中可用 S3 Storage Lens 指標精細程度的詳細資訊，請參閱下列清單：
+ **組織** – 組織中跨成員帳戶彙總的指標。S3 Storage Lens 會將成員帳戶的指標發佈到管理帳戶中的 CloudWatch。
  + **組織和帳戶** – 組織中成員帳戶的指標。
  + **組織和儲存貯體** – 組織中成員帳戶的 Amazon S3 儲存貯體指標。
+ **帳戶** (非組織層級) – 在您帳戶中跨儲存貯體彙總的指標。
+ **儲存貯體** (非組織層級) – 特定儲存貯體的指標。在 CloudWatch 中，S3 Storage Lens 會將這些指標發佈至 AWS 帳戶 建立 S3 Storage Lens 組態的 。S3 Storage Lens 只會針對非組織組態發佈這些指標。

## 維度
<a name="storage-lens-cloudwatch-dimensions"></a>

當 S3 Storage Lens 傳送資料至 CloudWatch 時，維度會連接至每個指標。維度是描述指標特性的類別。您可以使用維度來篩選 CloudWatch 傳回的結果。

例如，CloudWatch 中的所有 S3 Storage Lens 指標都有 `configuration_id` 維度。您可以使用此維度來區分與特定 S3 Storage Lens 組態相關聯的指標。`organization_id` 會識別組織層級指標。如需 CloudWatch 中維度的詳細資訊，請參閱《CloudWatch 使用者指南**》中的[維度](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Dimension)。

S3 Storage Lens 指標可以使用不同的維度，具體取決於指標的精細程度。例如，您可以使用 `organization_id`維度，依 AWS Organizations ID 篩選組織層級指標。不過，您無法將此維度用於儲存貯體和帳戶層級指標。如需詳細資訊，請參閱[使用維度篩選指標](storage-lens-cloudwatch-monitoring-cloudwatch.md#storage-lens-cloudwatch-monitoring-cloudwatch-dimensions)。

若要查看 S3 Storage Lens 組態可用的維度，請參閱下表。


|  **維度**  |  **Description**  |  **儲存貯體**  | **帳戶** |  **組織**  |  **組織和儲存貯體**  |  **組織和帳戶**  | 
| --- | --- | --- | --- | --- | --- | --- | 
| configuration\$1id |  指標中報告的 S3 Storage Lens 組態儀表板名稱  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| metrics\$1version |  S3 Storage Lens 指標的版本。指標版本的值固定為 `1.0`。  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| organization\$1id |  指標的 AWS Organizations ID  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| aws\$1account\$1number | 與指標 AWS 帳戶 相關聯的 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| aws\$1region | 指標 AWS 區域 的 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| bucket\$1name |  指標中報告的 S3 儲存貯體名稱  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-no.png)  | 
| storage\$1class |  指標中報告之儲存貯體的儲存體類別  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png)  | 
| record\$1type |  指標的精細程度：組織、帳戶、儲存貯體  | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png) 儲存貯體 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png) 帳戶 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png) 儲存貯體 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png) 帳戶 | ![\[Yes\]](http://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/images/icon-yes.png) 組織 | 

# 啟用 S3 Storage Lens 的 CloudWatch 發佈
<a name="storage-lens-cloudwatch-enable-publish-option"></a>

您可以將 S3 Storage Lens 指標發佈到 Amazon CloudWatch，以在 [CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)中建立統一的運作狀態檢視。您也可以使用 CloudWatch 功能 (例如警示和觸發動作、指標數學和異常偵測) 來監控 S3 Storage Lens 指標並對其採取動作。此外，CloudWatch API 操作可讓應用程式 (包括第三方供應商) 存取您的 S3 Storage Lens 指標。如需有關 CloudWatch 功能的詳細資訊，請參閱《[Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html)》。

S3 Storage Lens 指標會在擁有 S3 Storage Lens 組態的帳戶中發佈至 CloudWatch。在進階指標中啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中依組態 ID、帳戶、儲存貯體 （僅適用於儲存貯體層級指標）、區域和儲存類別存取帳戶層級和儲存貯體層級指標。在 CloudWatch 中不提供字首層級的指標。

您可以使用 S3 主控台、Amazon S3 REST APIs 和 AWS SDKs AWS CLI，為新的或現有的儀表板組態啟用 CloudWatch 支援。CloudWatch 發佈選項適用於升級至 S3 Storage Lens 進階指標和建議的儀表板。如需 S3 Storage Lens 進階指標和建議定價，請參閱 [Amazon S3 定價](https://aws.amazon.com/s3/pricing/)。不會產生額外的 CloudWatch 指標發佈費用；不過，儀表板、警示和 API 呼叫等其他 CloudWatch 費用則適用。

若要為 S3 Storage Lens 指標啟用 CloudWatch 發佈選項，請參閱下列主題。

**注意**  
S3 Storage Lens 指標是每日指標，每天向 CloudWatch 發佈一次。在 CloudWatch 中查詢 S3 Storage Lens 指標時，查詢的時段必須為 1 天 (86400 秒)。在每日 S3 Storage Lens 指標出現在 Amazon S3 主控台的 S3 Storage Lens 儀表板中之後，這些相同指標可能會需要幾個小時才會出現在 CloudWatch 中。首次啟用 S3 Storage Lens 指標的 CloudWatch 發佈選項時，您的指標最多可能需要 24 小時才能發佈到 CloudWatch。  
目前，S3 Storage Lens 指標無法透過 CloudWatch 串流取用。

## 使用 S3 主控台
<a name="storage-lens-cloudwatch-enable-publish-console"></a>

更新 S3 Storage Lens 儀表板時，您無法變更儀表板名稱或主要區域。您也無法變更預設儀表板的範圍，其範圍限定在整個帳戶的儲存體。

**更新 S3 Storage Lens 儀表板以啟用 CloudWatch 發佈**

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

1. 在左導覽窗格中，選擇 **S3 Storage Lens**、**Dashboards** (儀表板)。

1. 選擇您要編輯的儀表板，然後選擇 **Edit** (編輯)。

1. 在 **Metrics selection** (指標選擇) 下，選擇 **Advanced metrics and recommendations** (進階指標和建議)。

   進階指標和建議需支付額外費用。進階指標和建議包含資料查詢的 15 個月時段、字首層級彙總的用量指標、依儲存貯體彙總的活動指標、CloudWatch 發佈選項，以及協助您最佳化儲存成本，並套用資料保護最佳實務的內容相關建議。如需詳細資訊，請參閱 [Simple Storage Service (Amazon S3) 定價](https://aws.amazon.com/s3/pricing/)。

1. 在 **Select Advanced metrics and recommendations features** (選取進階指標和建議功能) 下，選取 **CloudWatch publishing** (CloudWatch 發佈)。
**重要**  
如果您的組態啟用用量指標的字首彙總，則字首層級指標將不會發佈至 CloudWatch。僅儲存貯體、帳戶和組織層級 S3 Storage Lens 指標發佈至 CloudWatch。

1. 選擇**儲存變更**。

**建立啟用 CloudWatch 支援的新 S3 Storage Lens 儀表板**

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

1. 在左導覽窗格中，選擇 **Storage Lens**、**Dashboards** (儀表板)。

1. 選擇 **Create dashboard (建立儀表板)**。

1. 在 **General** (一般) 下，定義下列組態選項：

   1. 針對 **Dashboard name** (儀表板名稱)，輸入儀表板名稱。

      儀表板名稱必須少於 65 個字元，且不得包含特殊字元或空格。建立儀表板後，您就無法變更儀表板名稱。

   1. 選擇儀表板的 **Home Region** (主要區域)。

      此儀表板範圍中所有包含區域的指標都會集中存放在此指定的主要區域。在 CloudWatch 中，主要區域也提供 S3 Storage Lens 指標。建立儀表板後，您就無法變更主要區域。

1. (選用) 若要新增標籤，請選擇 **Add tag** (新增標籤)，然後輸入標籤的 **Key** (鍵) 和 **Value** (值)。
**注意**  
您最多可為儀表板組態中新增 50 個標籤。

1. 定義您的組態範圍：

   1. 如果您要建立組織層級的組態，請選擇要包含在組態中的帳戶：**Include all accounts in your configuration** (將全部帳戶包含在組態中) 或者 **Limit the scope to your signed-in account** (將範圍限制在您的登入帳戶)。
**注意**  
建立包含所有帳戶的組織層級組態時，您只能包含或排除區域，而不是儲存貯體。

   1. 選擇您想要 S3 Storage Lens 在儀表板組態中包含的區域和儲存貯體，方法為執行下列動作：
      + 若要包含所有區域，請選擇 **Include Regions and buckets** (包含區域和儲存貯體)。
      + 若要包含特定區域，請清除 **Include all Regions** (包含所有區域)。在 **Choose Regions to include** (選擇要包含的區域) 下，選擇您想要 S3 Storage Lens 包含在儀表板中的區域。
      + 若要包含特定的儲存貯體，請清除 **Include all buckets** (包含所有儲存貯體)。在 **Choose buckets to include** (選擇要包含的儲存貯體) 下，選擇您想要 S3 Storage Lens 包含在儀表板中的儲存貯體。
**注意**  
您最多可以選擇 50 個儲存貯體。

1. 針對 **Metrics selection** (指標選擇)，選擇 **Advanced metrics and recommendations** (進階指標和建議)。

   如需有關進階指標和建議定價的詳細資訊，請參閱 [Amazon S3 定價](https://aws.amazon.com/s3/pricing/)。

1. 在 **Advanced metrics and recommendations features** (進階指標和建議功能) 下，選取您想要啟用的選項：
   + **Advanced metrics** (進階指標) 
   + **CloudWatch 發佈**
**重要**  
如果為您的 S3 Storage Lens 組態啟用字首彙總，則字首層級指標將不會發佈至 CloudWatch。僅儲存貯體、帳戶和組織層級 S3 Storage Lens 指標發佈至 CloudWatch。
   + **字首彙總**
**注意**  
如需進階指標和建議功能的詳細資訊，請參閱 [指標選擇](storage_lens_basics_metrics_recommendations.md#storage_lens_basics_metrics_selection)。

1. 如果您已啟用 **Advanced metrics** (進階指標)，請選取要在 S3 Storage Lens 儀表板中顯示的 **Advanced metrics categories** (進階指標類別)：
   + **活動指標**
   + **Detailed status code metrics** (詳細的狀態碼指標)
   + **Advanced cost optimization metrics** (進階成本最佳化指標)
   + **Advanced data protection metrics** (進階資料保護指標)

   如需指標類別的詳細資訊，請參閱 [指標類別](storage_lens_basics_metrics_recommendations.md#storage_lens_basics_metrics_types)。如需指標的完整清單，請參閱[Amazon S3 Storage Lens 指標詞彙表](storage_lens_metrics_glossary.md)。

1. (選用) 設定您的指標匯出。

   如需如何設定指標匯出的詳細資訊，請參閱步驟 [使用 S3 主控台](storage_lens_creating_dashboard.md#storage_lens_console_creating)。

1. 選擇 **Create dashboard (建立儀表板)**。

## 使用 AWS CLI
<a name="storage-lens-cloudwatch-enable-publish-cli"></a>

下列 AWS CLI 範例使用 S3 Storage Lens 組織層級進階指標和建議組態來啟用 CloudWatch 發佈選項。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。

```
aws s3control put-storage-lens-configuration --account-id=555555555555 --config-id=your-configuration-id --region=us-east-1 --storage-lens-configuration=file://./config.json

config.json
{
  "Id": "SampleS3StorageLensConfiguration",
  "AwsOrg": {
    "Arn": "arn:aws:organizations::123456789012:organization/o-abcdefgh"
  },
  "AccountLevel": {
    "ActivityMetrics": {
      "IsEnabled":true
    },
    "AdvancedCostOptimizationMetrics": {
      "IsEnabled":true
    },
    "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
    },
    "DetailedStatusCodesMetrics": {
      "IsEnabled":true
    },
    "BucketLevel": {
      "ActivityMetrics": {
        "IsEnabled":true
      },
      "AdvancedCostOptimizationMetrics": {
        "IsEnabled":true
      },
      "DetailedStatusCodesMetrics": {
        "IsEnabled":true
      },
      "PrefixLevel":{
        "StorageMetrics":{
          "IsEnabled":true,
          "SelectionCriteria":{
            "MaxDepth":5,
            "MinStorageBytesPercentage":1.25,
            "Delimiter":"/"
          }
        }
      }
    }
  },
  "Exclude": {
    "Regions": [
      "eu-west-1"
    ],
    "Buckets": [
      "arn:aws:s3:::amzn-s3-demo-source-bucket "
    ]
  },
  "IsEnabled": true,
  "DataExport": {
    "S3BucketDestination": {
      "OutputSchemaVersion": "V_1",
      "Format": "CSV",
      "AccountId": "111122223333",
      "Arn": "arn:aws:s3:::amzn-s3-demo-destination-bucket",
      "Prefix": "prefix-for-your-export-destination",
      "Encryption": {
        "SSES3": {}
      }
    },
    "CloudWatchMetrics": {
      "IsEnabled": true
    }
  }
}
```

## 使用適用於 Java 的 AWS 開發套件
<a name="storage-lens-cloudwatch-enable-publish-sdk"></a>

```
package aws.example.s3control;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3control.AWSS3Control;
import com.amazonaws.services.s3control.AWSS3ControlClient;
import com.amazonaws.services.s3control.model.AccountLevel;
import com.amazonaws.services.s3control.model.ActivityMetrics;
import com.amazonaws.services.s3control.model.BucketLevel;
import com.amazonaws.services.s3control.model.CloudWatchMetrics;
import com.amazonaws.services.s3control.model.Format;
import com.amazonaws.services.s3control.model.Include;
import com.amazonaws.services.s3control.model.OutputSchemaVersion;
import com.amazonaws.services.s3control.model.PrefixLevel;
import com.amazonaws.services.s3control.model.PrefixLevelStorageMetrics;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.S3BucketDestination;
import com.amazonaws.services.s3control.model.SSES3;
import com.amazonaws.services.s3control.model.SelectionCriteria;
import com.amazonaws.services.s3control.model.StorageLensAwsOrg;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;
import com.amazonaws.services.s3control.model.StorageLensDataExport;
import com.amazonaws.services.s3control.model.StorageLensDataExportEncryption;
import com.amazonaws.services.s3control.model.StorageLensTag;

import java.util.Arrays;
import java.util.List;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class CreateAndUpdateDashboard {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "Source Account ID";
        String exportAccountId = "Destination Account ID";
        String exportBucketArn = "arn:aws:s3:::amzn-s3-demo-destination-bucket"; // The destination bucket for your metrics export must be in the same Region as your S3 Storage Lens configuration.
        String awsOrgARN = "arn:aws:organizations::123456789012:organization/o-abcdefgh";
        Format exportFormat = Format.CSV;

        try {
            SelectionCriteria selectionCriteria = new SelectionCriteria()
                    .withDelimiter("/")
                    .withMaxDepth(5)
                    .withMinStorageBytesPercentage(10.0);
            PrefixLevelStorageMetrics prefixStorageMetrics = new PrefixLevelStorageMetrics()
                    .withIsEnabled(true)
                    .withSelectionCriteria(selectionCriteria);
            BucketLevel bucketLevel = new BucketLevel()
                    .withActivityMetrics(new ActivityMetrics().withIsEnabled(true))
                    .withAdvancedCostOptimizationMetrics(new AdvancedCostOptimizationMetrics().withIsEnabled(true))
                    .withAdvancedDataProtectionMetrics(new AdvancedDataProtectionMetrics().withIsEnabled(true))
                    .withDetailedStatusCodesMetrics(new DetailedStatusCodesMetrics().withIsEnabled(true))
                    .withPrefixLevel(new PrefixLevel().withStorageMetrics(prefixStorageMetrics));
            AccountLevel accountLevel = new AccountLevel()
                    .withActivityMetrics(new ActivityMetrics().withIsEnabled(true))
                    .withAdvancedCostOptimizationMetrics(new AdvancedCostOptimizationMetrics().withIsEnabled(true))
                    .withAdvancedDataProtectionMetrics(new AdvancedDataProtectionMetrics().withIsEnabled(true))
                    .withDetailedStatusCodesMetrics(new DetailedStatusCodesMetrics().withIsEnabled(true))
                    .withBucketLevel(bucketLevel);

            Include include = new Include()
                    .withBuckets(Arrays.asList("arn:aws:s3:::amzn-s3-demo-bucket"))
                    .withRegions(Arrays.asList("us-west-2"));

            StorageLensDataExportEncryption exportEncryption = new StorageLensDataExportEncryption()
                    .withSSES3(new SSES3());
            S3BucketDestination s3BucketDestination = new S3BucketDestination()
                    .withAccountId(exportAccountId)
                    .withArn(exportBucketArn)
                    .withEncryption(exportEncryption)
                    .withFormat(exportFormat)
                    .withOutputSchemaVersion(OutputSchemaVersion.V_1)
                    .withPrefix("Prefix");
            CloudWatchMetrics cloudWatchMetrics = new CloudWatchMetrics()
                    .withIsEnabled(true);
            StorageLensDataExport dataExport = new StorageLensDataExport()
                    .withCloudWatchMetrics(cloudWatchMetrics)
                    .withS3BucketDestination(s3BucketDestination);

            StorageLensAwsOrg awsOrg = new StorageLensAwsOrg()
                    .withArn(awsOrgARN);

            StorageLensConfiguration configuration = new StorageLensConfiguration()
                    .withId(configurationId)
                    .withAccountLevel(accountLevel)
                    .withInclude(include)
                    .withDataExport(dataExport)
                    .withAwsOrg(awsOrg)
                    .withIsEnabled(true);

            List<StorageLensTag> tags = Arrays.asList(
                    new StorageLensTag().withKey("key-1").withValue("value-1"),
                    new StorageLensTag().withKey("key-2").withValue("value-2")
            );

            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.putStorageLensConfiguration(new PutStorageLensConfigurationRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withStorageLensConfiguration(configuration)
                    .withTags(tags)
            );
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it and returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

## 使用 REST API
<a name="storage-lens-cloudwatch-enable-publish-api"></a>

若要使用 Amazon S3 REST API 來啟用 CloudWatch 發佈選項，您可以使用 [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_PutStorageLensConfiguration.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_PutStorageLensConfiguration.html)。

**後續步驟**  
啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中存取您的 S3 Storage Lens 指標。您也可以利用 CloudWatch 功能，在 CloudWatch 中監控和分析您的 S3 Storage Lens 資料。如需詳細資訊，請參閱下列主題：
+ [S3 Storage Lens 指標和維度](storage-lens-cloudwatch-metrics-dimensions.md)
+ [使用 CloudWatch 中的 S3 Storage Lens 指標](storage-lens-cloudwatch-monitoring-cloudwatch.md)

# 使用 CloudWatch 中的 S3 Storage Lens 指標
<a name="storage-lens-cloudwatch-monitoring-cloudwatch"></a>

您可以將 S3 Storage Lens 指標發佈到 Amazon CloudWatch，以在 [CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)中建立統一的運作狀態檢視。您也可以使用 CloudWatch 功能 (例如警示和觸發動作、指標數學和異常偵測) 來監控 S3 Storage Lens 指標並對其採取動作。此外，CloudWatch API 操作可讓應用程式 (包括第三方供應商) 存取您的 S3 Storage Lens 指標。如需有關 CloudWatch 功能的詳細資訊，請參閱《[Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html)》。

您可以使用 Amazon S3 主控台 AWS CLI、Amazon S3 REST APIs 和 AWS SDKs，為新的或現有的儀表板組態啟用 CloudWatch 發佈選項。CloudWatch 發佈選項適用於升級至 S3 Storage Lens 進階指標和建議的儀表板。如需 S3 Storage Lens 進階指標和建議定價，請參閱 [Amazon S3 定價](https://aws.amazon.com/s3/pricing/)。不會產生額外的 CloudWatch 指標發佈費用；不過，儀表板、警示和 API 呼叫等其他 CloudWatch 費用則適用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

S3 Storage Lens 指標會在擁有 S3 Storage Lens 組態的帳戶中發佈至 CloudWatch。在進階指標中啟用 CloudWatch 發佈選項後，您可以在 CloudWatch 中依組態 ID、帳戶、儲存貯體 （僅適用於儲存貯體層級指標）、區域和儲存類別存取帳戶層級和儲存貯體層級指標。在 CloudWatch 中不提供字首層級的指標。

**注意**  
S3 Storage Lens 指標是每日指標，每天向 CloudWatch 發佈一次。在 CloudWatch 中查詢 S3 Storage Lens 指標時，查詢的時段必須為 1 天 (86400 秒)。在每日 S3 Storage Lens 指標出現在 Amazon S3 主控台的 S3 Storage Lens 儀表板中之後，這些相同指標可能會需要幾個小時才會出現在 CloudWatch 中。首次啟用 S3 Storage Lens 指標的 CloudWatch 發佈選項時，您的指標最多可能需要 24 小時才能發佈到 CloudWatch。  
目前，S3 Storage Lens 指標無法透過 CloudWatch 串流取用。

如需在 CloudWatch 中使用 S3 Storage Lens 指標的詳細資訊，請參閱下列主題。

**Topics**
+ [使用 CloudWatch 儀表板](#storage-lens-cloudwatch-monitoring-cloudwatch-dashboards)
+ [設定警示、觸發動作和使用異常偵測](#storage-lens-cloudwatch-monitoring-cloudwatch-alarms)
+ [使用維度篩選指標](#storage-lens-cloudwatch-monitoring-cloudwatch-dimensions)
+ [使用指標數學計算新指標](#storage-lens-cloudwatch-monitoring-cloudwatch-metric-math)
+ [在圖形中使用搜尋表達式](#storage-lens-cloudwatch-monitoring-cloudwatch-search-expressions)

## 使用 CloudWatch 儀表板
<a name="storage-lens-cloudwatch-monitoring-cloudwatch-dashboards"></a>

您可以使用 CloudWatch 儀表板來監控 S3 Storage Lens 指標與其他應用程式指標，並建立統一的運作狀態檢視。儀表板是 CloudWatch 主控台中的可自訂首頁，您可於單一檢視中監控您的資源。

CloudWatch 具有廣泛的許可控制，不支援將存取限制為指標或維度的特定集。您帳戶或組織中具有 CloudWatch 存取權的使用者將可存取啟用 CloudWatch 支援選項之所有 S3 Storage Lens 組態的指標。您無法像在 S3 Storage Lens 中一樣管理特定儀表板的許可。如需 CloudWatch 許可的詳細資訊，請參閱《Amazon CloudWatch 使用者指南**》中的[管理 CloudWatch 資源的存取許可](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/iam-access-control-overview-cw.html)。

如需使用 CloudWatch 儀表板和設定許可的詳細資訊，請參閱《Amazon CloudWatch 使用者指南**》中的[使用 Amazon CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)和[共用 CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-dashboard-sharing.html)。

## 設定警示、觸發動作和使用異常偵測
<a name="storage-lens-cloudwatch-monitoring-cloudwatch-alarms"></a>

您可以設定 CloudWatch 警示，以便在 CloudWatch 中監視 S3 Storage Lens 指標，並在超出閾值時採取動作。例如，您可以設定警示，當 **Incomplete Multipart Upload Bytes** (未完成的分段上傳位元組) 指標連續三天超過 1 GB 時，傳送 Amazon SNS 通知。

您也可以啟用異常偵測，以持續分析您的 S3 Storage Lens 指標、判斷正常基準以及顯露異常情況。您可以建立以指標預期值為基礎的異常偵測警示。例如，您可以監控 **Object Lock Enabled Bytes** (已啟用物件鎖定的位元組) 指標的異常情況，以偵測未經授權即移除物件鎖定設定的情況。

如需詳細資訊和範例，請參閱《Amazon CloudWatch 使用者指南**》中的[使用 Amazon CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)和[從圖表上的指標建立警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create_alarm_metric_graph.html)。

## 使用維度篩選指標
<a name="storage-lens-cloudwatch-monitoring-cloudwatch-dimensions"></a>

您可以使用維度來篩選 CloudWatch 主控台中的 S3 Storage Lens 指標。例如，您可以依 `configuration_id`、`aws_account_number`、`aws_region`、`bucket_name` 等進行篩選。

S3 Storage Lens 支援每個帳戶的多種儀表板組態。這意味著不同的組態可以包含相同的儲存貯體。當這些指標在 CloudWatch 發佈時，儲存貯體在 CloudWatch 中會有重複的指標。若只要在 CloudWatch 中檢視特定 S3 Storage Lens 組態的指標，您可以使用 `configuration_id` 維度。依 `configuration_id` 篩選時，您只會看到與您所識別之組態相關聯的指標。

如需依組態 ID 篩選的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的[搜尋可用的指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/finding_metrics_with_cloudwatch.html)。

## 使用指標數學計算新指標
<a name="storage-lens-cloudwatch-monitoring-cloudwatch-metric-math"></a>

您可以使用指標數學，以查詢多個 S3 Storage Lens 指標，並使用數學表達式根據這些指標來建立新的時間序列。例如，您可以從「物件計數」中減去「加密物件」，為未加密物件建立新指標。您也可以建立一個指標，將 `StorageBytes` 除以 `ObjectCount` 而取得平均物件大小，或者將 `BytesDownloaded` 除以 `StorageBytes` 而取得一天存取的位元組數。

如需詳細資訊，請參閱《Amazon CloudWatch 使用者指南**》中的[使用指標數學](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html)。

## 在圖形中使用搜尋表達式
<a name="storage-lens-cloudwatch-monitoring-cloudwatch-search-expressions"></a>

使用 S3 Storage Lens 指標，您可以建立搜尋表達式。例如，您可以針對所有名為 **IncompleteMultipartUploadStorageBytes** 的指標建立搜尋表達式，然後將 `SUM` 新增至該表達式。使用此搜尋表達式，您可以在單一指標中查看儲存體所有維度的未完成分段上傳位元組總數。

此範例顯示您將用來為所有名為 **IncompleteMultipartUploadStorageBytes** 的指標建立搜尋表達式的語法。

```
SUM(SEARCH('{AWS/S3/Storage-Lens,aws_account_number,aws_region,configuration_id,metrics_version,record_type,storage_class} MetricName="IncompleteMultipartUploadStorageBytes"', 'Average',86400))
```

如需此語法的詳細資訊，請參閱《Amazon CloudWatch 使用者指南**》中的 [CloudWatch 搜尋表達式語法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/search-expression-syntax.html)。若要使用搜尋表達式建立 CloudWatch 圖表，請參閱《Amazon CloudWatch 使用者指南**》中的[使用搜尋表達式建立 CloudWatch 圖表](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-search-expression.html)。