建立要監控的 CloudWatch 警示 AWS IoT - AWS IoT Core

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

建立要監控的 CloudWatch 警示 AWS IoT

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

您可以在 看到 CloudWatch 警示可以監控的所有指標AWS IoT 指標和維度

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

  1. 建立名為 的 Amazon SNS主題things-not-connecting-successfully,並記錄其 Amazon Resource Name (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. 建立名為 的 Amazon SNS主題things-not-publishing-data,並記錄其 Amazon Resource Name (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. 建立名為 的 Amazon SNS主題things-shadow-updates-rejected,並記錄其 Amazon Resource Name (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 警示?

Jobs 服務提供 CloudWatch 指標供您監控任務。您可以建立 CloudWatch 警示來監控任何 任務指標

下列命令會建立 CloudWatch 警示,以監控任務的失敗任務執行總數 SampleOTAJob 當超過 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 警示,以監控任務的失敗任務執行次數 SampleOTAJob 在指定期間內。然後,當在此期間有超過五個任務執行失敗時,會通知您。警示每 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