本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用亞馬遜監控AWS DataSync活動 CloudWatch
您可以AWS DataSync使用 Amazon CloudWatch 來監控;該服務會收集並處理 DataSync為可讀且近乎即時的指標。這些統計資料會保留 15 個月。
根據預設, DataSync 指標資料每隔 5 分鐘會自動傳送到 CloudWatch 。如需詳細資訊,請參閱什麼是 Amazon CloudWatch、 CloudWatch 事件和 CloudWatch 日誌? 在亞馬遜 CloudWatch 用戶指南。
存取亞馬遜 CloudWatch 指標 DataSync
Amazon CloudWatch 提供指標,您可以使用這些指標取得 DataSync 效能相關資訊和疑難排解問題。您可以使用下列工具查看的 CloudWatch 量度: DataSync
-
CloudWatch 控制台
-
CloudWatch CLI
-
CloudWatch API
-
DataSync 主控台 (工作執行頁面)
如需詳細資訊,請參閱 Amazon 使用者指南中的使 CloudWatch 用 Amazon 指 CloudWatch 標。
CloudWatch 度量 DataSync
AWS/DataSync
命名空間包含下列指標。
指標 | 描述 |
---|---|
|
套用壓縮之後透過網路傳輸的實體位元組數。在大多數情況下,除非數據不可壓縮, 單位:位元組 |
|
已在目的地位置完成準備的位元組總數量。 單位:位元組 |
|
已在來源位置完成準備的位元組總數量。 單位:位元組 |
|
傳輸所涉及的位元組總位元組總位元組總位元組總位元組 如需透過網路傳送的位元組總數,請參閱 單位:位元組 |
|
已在目的地位置驗證過的位元組總數量。 單位:位元組 |
|
已在來源位置驗證過的位元組總數量。 單位:位元組 |
|
已傳輸到目的地位置的所有檔案的總邏輯大小。 單位:位元組 |
|
已在目的地位置完成準備的檔案總數量。 單位:計數 |
|
已在來源位置完成準備的檔案總數量。 單位:計數 |
|
透過網路傳輸的檔案或中繼資料實際數量。在 如果傳輸過程發生失敗,此值可能會小於 單位:計數 |
|
已在目的地位置驗證過的檔案總數量。 單位:計數 |
|
已在來源位置驗證過的檔案總數量。 單位:計數 |
指標的維 DataSync 度
DataSync 指標使用AWS/DataSync
命名空間,並提供下列維度的維度的維度的維度
-
AgentId— 代理程式的唯一 ID。
-
TaskId— 任務的唯一 ID。其格式為
task-01234567890abcdef
。
亞馬遜 EventBridge 活動 DataSync
亞馬遜 EventBridge 事件描述了 DataSync 資源的變化。您可以設定規則來比對這些事件,並將這些事件路由到一或多個目標函數或串流。盡可能發出事件。
下列 EventBridge 事件可用於 DataSync。
Agent state changes | |
---|---|
事件 | 描述 |
Online | The agent is configured properly and is available to use. This status is the normal running status for an agent. |
Offline | The agent's VM is turned off or the agent is in an unhealthy state and has been out of contact with the service for 5 minutes or longer. When the issue that caused the unhealthy state is resolved, the agent returns to ONLINE status. |
Location state changes | |
事件 | 描述 |
Adding | DataSync is adding a location. |
Available | The location is created and is available to use. |
Task state changes | |
事件 | 描述 |
Available | The task was created and is ready to start. |
Running | The task is in progress and functioning properly. |
Unavailable | The task isn't configured properly and can't be used. You may see this when an agent associated with the task goes offline. |
Queued | Another task is running and using the same agent. DataSync runs tasks in series (first in, first out). |
Task execution state changes | |
事件 | 描述 |
Queueing | DataSync is waiting for another task that's using the same agent to finish. |
Launching | DataSync is initializing the task execution. |
Preparing | DataSync is determining which files need to be transferred. |
Transferring | DataSync is performing the actual transfer of your data. |
Verifying | DataSync performs a full data and metadata integrity verification to ensure that the data in your destination is an exact copy of your source. |
Success | The transfer is successful. |
Error | The transfer failed. |
允許 DataSync 將日誌上傳到亞馬遜日 CloudWatch 誌群組
DataSync 需要足夠的權限才能將記錄檔傳送到您的記 CloudWatch 錄群組。當您使用主控台建立工作時, DataSync 可以使用正確的許可自動建立 IAM 資源政策。
下列範例是授與這些權限的資源策略。
{ "Statement": [ { "Sid": "DataSyncLogsToCloudWatchLogs", "Effect": "Allow", "Action": [ "logs:PutLogEvents", "logs:CreateLogStream" ], "Principal": { "Service": "datasync.amazonaws.com" }, "Condition": { "ArnLike": { "aws:SourceArn": [ "arn:aws:datasync:
region
:account-id
:task/*" ] }, "StringEquals": { "aws:SourceAccount": "account-id
" } }, "Resource": "arn:aws:logs:region
:account-id
:log-group:*:*" } ], "Version": "2012-10-17" }
此原則會使用條件陳述式來確保只有來自指定帳戶的 DataSync 工作才能存取指定的 CloudWatch 記錄群組。我們建議在這些條件陳述式中使用aws:SourceArn
和aws:SourceAccount
全域條件內容索引鍵,以防止混淆的副問題。如需詳細資訊,請參閱預防跨服務混淆代理人。
若要指定一或多個工作,請
以工作所在位AWS 區域置的 DataSync [Region] 程式碼取代,並取region
代為包含工作之帳戶的AWS 帳戶 ID。若要指定 CloudWatch 記錄群組,請取代相同的值。您也可以修改account-id
Resource
陳述式以指定特定的記錄群組為目標。如需使用SourceArn
和的詳細資訊SourceAccount
,請參閱 IAM 使用者指南中的全域條件金鑰。
若要套用政策,請將此政策陳述式儲存至本機電腦上的檔案。然後執行下列AWS CLI命令以套用資源策略:
aws logs put-resource-policy --policy-name trustDataSync --policy-document file://
full-path-to-policy-file
使用相同的命令運行此命令,AWS 帳戶並且您AWS 區域是否激活了 DataSync代理。
如需詳細資訊,請參閱《Amazon CloudWatch Logs 使用者指南》中的使用日誌群組和日誌串流。
從命令列監控您的 DataSync 工作
您可以使用AWS Command Line Interface或標準 Unixwatch
公用程式來追蹤您的 DataSync 任務。
使用監視您的工作AWS CLI
若要使用 CLI 監視 DataSync 工作的狀態,請使用describe-task-execution
指令。
aws datasync describe-task-execution \ --task-execution-arn 'arn:aws:datasync:
region
:account-id
:task/task-id
/execution/task-execution-id
'
此命令會傳回類似如下的任務執行資訊。
{ "BytesCompressed": 0, "BytesTransferred": 0, "BytesWritten": 0, "EstimatedFilesToTransfer": 0, "EstimatedBytesToTransfer": 0, "FilesTransferred": 0, "Options": { "VerifyMode": "POINT_IN_TIME_CONSISTENT", "Atime": "BEST_EFFORT", "Mtime": "PRESERVE", "Uid": "INT_VALUE", "Gid": "INT_VALUE", "PreserveDevices": "NONE", "PosixPermissions": "PRESERVE", "PreserveDeletedFiles": "PRESERVE", "OverwriteMode": "NEVER", "TaskQueueing": "ENABLED" }, "Result": { "PrepareDuration": 4355, "PrepareStatus": "Ok", "TransferDuration": 5889, "TransferStatus": "Ok", "VerifyDuration": 4538, "VerifyStatus": "Pending" }, "StartTime": 1532658526.949, "Status": "VERIFYING", "TaskExecutionArn": "arn:aws:datasync:us-east-1:112233445566:task/task-08de6e6697796f026/execution/exec-04ce9d516d69bd52f" }
如果任務執行成功,則 Status (狀態) 的值會變成 SUCCESS (成功)。如果 describe-task-execution
命令失敗,結果所傳送的錯誤代碼可協助您對問題進行故障診斷。如需有關錯誤碼的資訊,請參閱 DataSync API 參考資料TaskExecutionResultDetail中的。
使用watch
公用程式監視您的工作
要從命令行實時監視任務的進度,您可以使用標準的 Unix 實用watch
程序。工作執行持續時間值會以毫秒為單位測量。
watch
公用程式無法辨識 DataSync 別名。下列範例示範如何直接呼叫 CLI。
# pass '-n 1' to update every second and '-d' to highlight differences $ watch -n 1 -d \ "aws datasync describe-task-execution --task-execution-arn 'arn:aws:datasync:
region
:account-id
:task/task-id
/execution/taskexecution-id
'"