

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

# 適用於 Amazon SQS 的可用 CloudWatch 指標
<a name="sqs-available-cloudwatch-metrics"></a>

Amazon SQS 會傳送下列指標至 CloudWatch。

**注意**  
對於某些指標，結果是近似值，因為 Amazon SQS 的分散式架構。在大多數情況下，計數應接近佇列中的實際訊息數目。

## Amazon SQS 指標
<a name="sqs-metrics"></a>

Amazon SQS 會自動將操作指標發佈至 `AWS/SQS` 命名空間下的 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。這些指標可協助您監控佇列運作狀態和效能。由於 SQS 的分散式本質，許多值都是近似值，但對於大多數的操作決策來說都足夠準確。

**注意**  
只有在佇列作用中時，所有指標才會發出非負值。
在至少傳送一則訊息之前，不會發出某些指標 （例如 `SentMessageSize`)。


| 指標 | Description | 單位 | 報告行為 | 重要備註 | 
| --- | --- | --- | --- | --- | 
| ApproximateAgeOfOldestMessage | 佇列中最舊未處理訊息的存留期。 | 秒鐘 | 如果佇列包含至少一個作用中訊息，則回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| ApproximateNumberOfGroupsWithInflightMessages | 僅適用於 FIFO。具有一或多個傳輸中訊息的訊息群組數量。 | 計數 | 如果 FIFO 佇列處於作用中狀態，則回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| ApproximateNumberOfMessagesDelayed | 佇列中延遲且無法立即擷取的訊息數量。 | 計數 | 如果佇列中存在延遲訊息，則回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| ApproximateNumberOfMessagesNotVisible | 已接收但尚未刪除或過期的傳輸中訊息數量。 | 計數 | 如果傳輸中的訊息存在，則回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| ApproximateNumberOfMessagesVisible | 目前可供擷取和處理的訊息數量。 | 計數 | 如果佇列處於作用中狀態，則回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| NumberOfEmptyReceives1 | 未傳回訊息的 [ReceiveMessage](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html) API 呼叫數目。 | 計數 | 在接收操作期間報告。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| NumberOfDeduplicatedSentMessages | 僅適用於 FIFO。已刪除但未新增至佇列的已傳送訊息數量。 | 計數 | 偵測到重複MessageDeduplicationId值或內容時回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| NumberOfMessagesDeleted1 | 成功從佇列刪除的訊息數量。 | 計數 | 使用有效的接收控點報告每個刪除請求。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
| NumberOfMessagesReceived1 | [ReceiveMessage](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html) API 傳回的訊息數量。 | 計數 | 在接收操作期間報告。 |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html)  | 
|  NumberOfMessagesSent1 | 成功新增至佇列的訊息數量。 | 計數 | 每次手動傳送成功時回報。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  SentMessageSize1  | 成功傳送至佇列的訊息大小。 | 位元組 | 在傳送至少一個訊息之前不會發出。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  ApproximateNumberOfNoisyGroups | 在公平佇列中被視為雜訊的訊息群組數量。雜訊訊息群組代表多租用戶佇列的雜訊鄰近租用戶。 | 計數 | [如果佇列處於作用中狀態，](monitoring-using-cloudwatch.md)則會報告非負值。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  ApproximateNumberOfMessagesVisibleInQuietGroups | 可見的訊息數量，不包括來自雜訊訊息群組的訊息。 | 計數 | [如果佇列處於作用中狀態，](monitoring-using-cloudwatch.md)則會報告非負值。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  ApproximateNumberOfMessagesNotVisibleInQuietGroups | 傳輸中的訊息數量，不包括來自雜訊訊息群組的訊息。 | 計數 | [如果佇列處於作用中狀態，](monitoring-using-cloudwatch.md)則會報告非負值。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  ApproximateNumberOfMessagesDelayedInQuietGroups | 排除來自雜訊訊息群組的訊息，且延遲且無法立即讀取的訊息數量。當佇列設定為[延遲佇列](sqs-delay-queues.md)，或使用延遲參數傳送訊息時，會發生延遲訊息。 | 計數 | [如果佇列處於作用中狀態，](monitoring-using-cloudwatch.md)則會報告非負值。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 
|  ApproximateAgeOfOldestMessageInQuietGroups | 佇列中最舊未刪除訊息的存留期，不包括來自雜訊訊息群組的訊息。 | 秒鐘 | [如果佇列處於作用中狀態，](monitoring-using-cloudwatch.md)則會報告非負值。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html) | 

1 這些指標反映系統層級的活動，可能包括重試、重複或延遲訊息。請勿使用原始計數來估計即時佇列狀態，而不考慮訊息生命週期行為。

## 無效字母佇列 (DLQs) 和 CloudWatch 指標
<a name="dlq-cloudwatch-metrics"></a>

使用 DLQs 時，請務必了解 Amazon SQS 指標的行為：
+ **`NumberOfMessagesSent`** – 此指標對 DLQs 的行為不同：
  + **手動傳送** – 此指標會擷取手動傳送至 DLQ 的訊息。
  + **自動重新驅動** – 此指標**不會**擷取因處理失敗而自動移至 DLQ 的訊息。因此， `NumberOfMessagesSent`和 `NumberOfMessagesReceived`指標可能會顯示 DLQs 的差異。
+ **DLQs 的建議指標** – 若要監控 DLQ 的狀態，請使用 `ApproximateNumberOfMessagesVisible` 指標。此指標表示目前可在 DLQ 中處理的訊息數量。

## 公平佇列和 CloudWatch 指標
<a name="fair-queues-cloudwatch-metrics"></a>

當您使用[公平佇列](sqs-fair-queues.md)時，Amazon SQS 會發出下列其他指標：
+ `ApproximateNumberOfNoisyGroups`
+ `ApproximateNumberOfMessagesVisibleInQuietGroups`
+ `ApproximateNumberOfMessagesNotVisibleInQuietGroups`
+ `ApproximateNumberOfMessagesDelayedInQuietGroups`
+ `ApproximateAgeOfOldestMessageInQuietGroups`

**注意**  
每個`QuietGroup`指標都是同等標準佇列層級`Approximate`指標的子集，但排除來自雜訊鄰近群組的訊息。

**雜訊群組**  
雜訊訊息群組代表多租用戶佇列的雜訊鄰近租用戶。

**靜音群組**  
排除雜訊群組的訊息群組。

**觀察 SQS 公平佇列行為**

若要監控 Amazon SQS 公平佇列的效果，您可以將`Approximate..InQuietGroups`指標與標準佇列層級指標進行比較。在特定租用戶的流量激增期間，一般佇列層級指標可能會顯示不斷增加的待處理項目或較舊的訊息存留期。不過，您可以單獨查看安靜的群組，找出大多數非雜訊訊息群組或租戶不會受到影響，並提供受影響訊息群組總數的預估值。

 雖然這些新指標提供 Amazon SQS 公平佇列行為的良好概觀，但了解哪些特定租用戶導致負載是有益的。[Amazon CloudWatch 貢獻者洞察](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContributorInsights.html)可讓您查看有關前 N 名貢獻者的指標、唯一貢獻者的總數及其用量。這在您處理數千個租用戶時特別有用，否則在發出傳統指標時會導致高基數資料 （和成本）。

 如需公平佇列的監控組態範例，請參閱 [GitHub](https://github.com/aws-samples/sample-amazon-sqs-fair-queues) 上的範例。

## Amazon SQS 指標的維度
<a name="sqs-metric-dimensions"></a>

CloudWatch 中的 Amazon SQS 指標使用單一維度：**`QueueName`**。所有指標資料都會依佇列的名稱分組和篩選。

## 監控秘訣
<a name="monitoring-tips"></a>

使用關鍵指標和 CloudWatch 警示有效監控 SQS，以偵測佇列待處理項目、最佳化效能，並保持在服務限制內。
+ 根據 設定 [CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)`ApproximateNumberOfMessagesVisible`，以捕捉待處理項目成長。
+ 監控`NumberOfEmptyReceives`以調整輪詢頻率並降低 API 成本。
+ 在 FIFO 佇列`ApproximateNumberOfGroupsWithInflightMessages`中使用 來診斷輸送量限制。
+ 檢閱 [SQS 配額](sqs-quotas.md)以了解指標閾值和服務限制。