建立要監視的 CloudWatch 警報 AWS IoT - AWS IoT Core

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

建立要監視的 CloudWatch 警報 AWS IoT

您可以建立 CloudWatch 警示,在警示狀態變更時傳送 Amazon SNS 訊息。警示會在您指定的期間,監看單一指標。當指標值在數個期間內超過指定的閾值時,會執行一或多個動作。此動作可為傳送至 Amazon SNS 主題或 Auto Scaling 政策的通知。警示只會針對持續的狀態變更觸發動作。 CloudWatch 警示不會僅因為處於特定狀態而觸發動作;狀態必須已變更並維持指定數目的期間。

您可以查看 CloudWatch 警報可以監控的所有指標AWS IoT 量度和維度

如何每天都在我的物件連線失敗時收到通知?

  1. 建立名為 things-not-connecting-successfully 的 Amazon SNS 主題,並記錄其 Amazon 資源名稱 (ARN)。此程序會將您主題的 ARN 稱為 sns-topic-arn

    如需如何建立 Amazon SNS 通知的詳細資訊,請參閱 Amazon SNS 入門

  2. 建立警示。

    aws cloudwatch put-metric-alarm \ --alarm-name ConnectSuccessAlarm \ --alarm-description "Alarm when my Things don't connect successfully" \ --namespace AWS/IoT \ --metric-name Connect.Success \ --dimensions Name=Protocol,Value=MQTT \ --statistic Sum \ --threshold 10 \ --comparison-operator LessThanThreshold \ --period 86400 \ --evaluation-periods 1 \ --alarm-actions sns-topic-arn
  3. 測試警示。

    aws cloudwatch set-alarm-state --alarm-name ConnectSuccessAlarm --state-reason "initializing" --state-value OK
    aws cloudwatch set-alarm-state --alarm-name ConnectSuccessAlarm --state-reason "initializing" --state-value ALARM
  4. 確認警示是否出現在CloudWatch 主機中。

如何每天都在我的物件並未推送資料時收到通知?

  1. 建立名為 things-not-publishing-data 的 Amazon SNS 主題,並記錄其 Amazon 資源名稱 (ARN)。此程序會將您主題的 ARN 稱為 sns-topic-arn

    如需如何建立 Amazon SNS 通知的詳細資訊,請參閱 Amazon SNS 入門

  2. 建立警示。

    aws cloudwatch put-metric-alarm \ --alarm-name PublishInSuccessAlarm\ --alarm-description "Alarm when my Things don't publish their data \ --namespace AWS/IoT \ --metric-name PublishIn.Success \ --dimensions Name=Protocol,Value=MQTT \ --statistic Sum \ --threshold 10 \ --comparison-operator LessThanThreshold \ --period 86400 \ --evaluation-periods 1 \ --alarm-actions sns-topic-arn
  3. 測試警示。

    aws cloudwatch set-alarm-state --alarm-name PublishInSuccessAlarm --state-reason "initializing" --state-value OK
    aws cloudwatch set-alarm-state --alarm-name PublishInSuccessAlarm --state-reason "initializing" --state-value ALARM
  4. 確認警示是否出現在CloudWatch 主機中。

如何每天都在我的物件的影子更新遭拒時收到通知?

  1. 建立名為 things-shadow-updates-rejected 的 Amazon SNS 主題,並記錄其 Amazon 資源名稱 (ARN)。此程序會將您主題的 ARN 稱為 sns-topic-arn

    如需如何建立 Amazon SNS 通知的詳細資訊,請參閱 Amazon SNS 入門

  2. 建立警示。

    aws cloudwatch put-metric-alarm \ --alarm-name UpdateThingShadowSuccessAlarm \ --alarm-description "Alarm when my Things Shadow updates are getting rejected" \ --namespace AWS/IoT \ --metric-name UpdateThingShadow.Success \ --dimensions Name=Protocol,Value=MQTT \ --statistic Sum \ --threshold 10 \ --comparison-operator LessThanThreshold \ --period 86400 \ --unit Count \ --evaluation-periods 1 \ --alarm-actions sns-topic-arn
  3. 測試警示。

    aws cloudwatch set-alarm-state --alarm-name UpdateThingShadowSuccessAlarm --state-reason "initializing" --state-value OK
    aws cloudwatch set-alarm-state --alarm-name UpdateThingShadowSuccessAlarm --state-reason "initializing" --state-value ALARM
  4. 確認警示是否出現在CloudWatch 主機中。

如何為工作建立 CloudWatch 警示?

「工作」服務提供 CloudWatch 指標,供您監視工作。您可以創建 CloudWatch 警報以監視任何警報任務指標

下列命令會建立 CloudWatch 警示,以監視工作 SampleOTAJob Job 失敗的工作執行總數,並在超過 20 個工作執行失敗時通知您。警示每 300 秒會檢查報告的值,以監控任務指標 FailedJobExecutionTotalCount。當單一報告值大於 20 時,便會啟動警示,表示自任務啟動以來,失敗的任務執行次數超過 20 次。當警示關閉時,會傳送通知給所提供的 Amazon SNS 主題。

aws cloudwatch put-metric-alarm \ --alarm-name TotalFailedJobExecution-SampleOTAJob \ --alarm-description "Alarm when total number of failed job execution exceeds the threshold for SampleOTAJob" \ --namespace AWS/IoT \ --metric-name FailedJobExecutionTotalCount \ --dimensions Name=JobId,Value=SampleOTAJob \ --statistic Sum \ --threshold 20 \ --comparison-operator GreaterThanThreshold \ --period 300 \ --unit Count \ --evaluation-periods 1 \ --alarm-actions arn:aws:sns:<AWS_REGION>:<AWS_ACCOUNT_ID>:SampleOTAJob-has-too-many-failed-job-ececutions

下列命令會建立 CloudWatch 警示,以監視指定期間內工作 SampleOta Job 失敗的工作執行次數。然後,當在此期間有超過五個任務執行失敗時,會通知您。警示每 3600 秒會檢查報告的值,以監控任務指標 FailedJobExecutionCount。當單一報告值大於 5 時,便會啟動警示,表示在過去一小時內,失敗的任務執行次數超過 5 次。當警示關閉時,會傳送通知給所提供的 Amazon SNS 主題。

aws cloudwatch put-metric-alarm \ --alarm-name FailedJobExecution-SampleOTAJob \ --alarm-description "Alarm when number of failed job execution per hour exceeds the threshold for SampleOTAJob" \ --namespace AWS/IoT \ --metric-name FailedJobExecutionCount \ --dimensions Name=JobId,Value=SampleOTAJob \ --statistic Sum \ --threshold 5 \ --comparison-operator GreaterThanThreshold \ --period 3600 \ --unit Count \ --evaluation-periods 1 \ --alarm-actions arn:aws:sns:<AWS_REGION>:<AWS_ACCOUNT_ID>:SampleOTAJob-has-too-many-failed-job-ececutions-per-hour