

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

# 監控索引儲存體用量
<a name="index-usage-monitoring"></a>

索引用量日誌可讓您了解 Amazon Quick 索引儲存在知識庫和空間中的使用方式，包括檔案上傳。您可以使用這些日誌來追蹤成長趨勢、識別最大的來源、偵測非預期的峰值，以及規劃容量。

查詢索引用量資料之前，您必須設定`INDEX_USAGE_LOGS`交付。如需設定交付的指示，請參閱 [使用 CloudWatch Logs 監控 Amazon Quick](monitoring-cloudwatch-logs.md)。

## 日誌結構描述
<a name="index-usage-monitoring-schema"></a>

每個索引用量日誌事件都包含跨所有 Amazon Quick 日誌類型共用的常見欄位，例如 `resource_arn`、`event_timestamp`、`account_id`、 `log_type`和 `user_arn`。事件也包含下列索引特定的欄位：


**索引用量日誌欄位**  

| 欄位 | Type | 說明 | 
| --- | --- | --- | 
| consumed\_index\_size | Integer | 整個索引消耗的總大小 （以位元組為單位）。這是授權總數。 | 
| source\_type | String | SPACE 或 KB | 
| source\_name | String | 顯示空間或知識庫的名稱。 | 
| source\_arn | String | 來源的完整 ARN。 | 
| consumed\_source\_size | Integer | 此個別來源消耗的大小 （以位元組為單位）。 | 
| consumed\_source\_doc\_count | Integer | 此來源中的文件數量。 | 

**注意**  
事件會在變更時依來源發佈。並非所有來源都會每天發出事件。若要重建目前狀態，請使用每個 的最新事件`source_arn`。

## CloudWatch Logs Insights 查詢
<a name="index-usage-monitoring-queries"></a>

下列 CloudWatch Logs Insights 查詢可協助您分析索引用量資料。所有查詢都會使用 模式`stats latest(field) by source_arn`，以取得每個來源的最新狀態。然後，查詢會視需要彙總。以您的日誌群組名稱取代 {{YOUR\_LOG\_GROUP}}。

### 依來源類型區分的大小 （與 Spaces 相比的知識基礎）
<a name="index-usage-query-kb-vs-spaces"></a>

顯示知識庫和空間之間的總大小分割。

```
fields @timestamp, source_type, source_arn, consumed_source_size
| stats latest(consumed_source_size) as latest_size, latest(source_type) as type by source_arn
| stats sum(latest_size) as total_size by type
```

### 隨時間變化的索引大小總計
<a name="index-usage-query-total-over-time"></a>

使用 `consumed_index_size` 欄位顯示索引大小趨勢。

```
fields @timestamp, consumed_index_size
| stats latest(consumed_index_size) as total_index_size by bin(1d) as day
| sort day asc
```

### 依大小排名前列的知識庫
<a name="index-usage-query-top-kb"></a>

顯示依大小排名的前 20 個知識庫。

```
fields @timestamp, source_type, source_arn, source_name, consumed_source_size
| filter source_type = "KB"
| stats latest(consumed_source_size) as latest_size, latest(source_name) as name by source_arn
| sort latest_size desc
| limit 20
```

### 依大小排列的頂部空間
<a name="index-usage-query-top-spaces"></a>

顯示依大小排名的前 20 個空格。

```
fields @timestamp, source_type, source_arn, source_name, consumed_source_size
| filter source_type = "SPACE"
| stats latest(consumed_source_size) as latest_size, latest(source_name) as name by source_arn
| sort latest_size desc
| limit 20
```

### 所有來源詳細資訊
<a name="index-usage-query-all-sources"></a>

顯示每個來源的最新狀態，包括大小、類型、名稱、文件計數和上次更新時間。

```
fields @timestamp, source_type, source_name, consumed_source_size, consumed_source_doc_count, source_arn
| stats latest(consumed_source_size) as latest_size, latest(source_type) as type, latest(source_name) as name, latest(consumed_source_doc_count) as doc_count, latest(@timestamp) as last_updated by source_arn
| sort latest_size desc
| limit 100
```

### 依大小總計排名前列的使用者
<a name="index-usage-query-top-users"></a>

顯示前 20 名使用者，依其所有來源的總來源大小排名。

```
fields @timestamp, user_arn, source_arn, consumed_source_size
| parse user_arn "*:user/*/*" as @prefix, @namespace, @username
| stats latest(consumed_source_size) as latest_size, latest(@username) as user by source_arn
| stats sum(latest_size) as total_size by user
| sort total_size desc
| limit 20
```

## 建立 CloudWatch 儀表板
<a name="index-usage-monitoring-dashboard"></a>

您可以建立 CloudWatch 儀表板，以視覺化索引用量指標。使用 CloudWatch 主控台建立儀表板，並使用上一節的查詢新增 Logs Insights 小工具。

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

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

1. 選擇**建立儀表板**並輸入名稱 （例如，`IndexUsageMetrics`)。

1. 使用**日誌**小工具類型新增小工具。選取您的索引用量日誌群組，並貼上上一節的查詢。

**提示**  
針對來源類型明細使用圓餅圖視覺化。使用折線圖表示隨時間變化的大小。使用最佳來源的長條圖。資料表視覺化非常適合所有來源詳細資訊查詢。