跳至內容

如何使用統一 CloudWatch 代理程式來解決日誌時間戳記錯誤?

1 分的閱讀內容
0

我想使用統一 Amazon CloudWatch 代理程式來解決日誌時間戳記錯誤。

簡短說明

統一 CloudWatch 代理程式使用 PutLogEvents API,將一批日誌事件上傳至 Amazon CloudWatch Logs。CloudWatch 不會接受超過未來 2 小時或早於 14 天前的批次日誌事件。此外,CloudWatch 也不會接受發生時間早於日誌群組保留期的日誌事件。

當日誌時間戳記超出可接受的時間範圍時,您可能會收到類似於以下其中之一的錯誤訊息:

  • <timestamp><Log Group Name><Log Stream Name><actual log timestamp><current timestamp>「 E! [outputs.cloudwatchlogs] The log entry in (/() with timestamp () comparing to the current time ( m=+100) is out of accepted time range.Discard the log entry.」
  • <timestamp><Log Group Name><Log Stream Name>「 W! [outputs.cloudwatchlogs] 1 log events for log '/(' are expired.」

解決方法

若要解決此錯誤,請完成以下步驟:

  1. 在統一 CloudWatch 代理程式組態檔案中新增 timestamp_format,以指定時間戳記格式。如果單一日誌項目包含兩個符合該格式的時間戳記,CloudWatch 會使用第一個時間戳記。
  2. (選用) 從統一 CloudWatch 代理程式組態檔案中移除 timestamp_format<br id=hardline_break/> **注意:**如果您省略此欄位,CloudWatch 會使用目前時間。
  3. 重新啟動統一 CloudWatch 代理程式,然後確認 CloudWatch 使用的是目前時間。

相關資訊

如何解決統一 CloudWatch 代理程式不推送日誌事件的問題?

AWS 官方已更新 6 個月前