创建要监控的 CloudWatch 警报 Amazon IoT - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建要监控的 CloudWatch 警报 Amazon IoT

您可以创建一个 CloudWatch 警报,在警报状态发生变化时发送 Amazon SNS 消息。警报会在您规定的时间范围内监控某一项指标。当指标的值在多个时间段内超过给定阈值时,将执行一项或多项操作。操作是一个发送到 Amazon SNS 主题或 Auto Scaling 策略的通知。警报仅针对持续的状态变化触发操作。 CloudWatch 警报不会仅仅因为它们处于特定状态而触发操作;该状态必须已更改并维持了指定的时间段。

您可以查看 CloudWatch 警报可以监控的所有指标Amazon IoT 指标和维度

我如何知道事物每天是否成功建立连接?

  1. 创建名为 things-not-connecting-successfully 的 Amazon SNS 主题,并记录其 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. 创建名为 things-not-publishing-data 的 Amazon SNS 主题,并记录其 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. 创建名为 things-shadow-updates-rejected 的 Amazon SNS 主题,并记录其 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 警报?

作业服务提供 CloudWatch 指标供您监控作业。您可以创建 CloudWatch 警报来监控任意 任务指标

以下命令创建 CloudWatch 警报以监控 Job s ampleotaJo b 的失败任务执行总数,并在超过 20 个任务执行失败时通知您。警报通过每 300 秒检查报告值来监控 Jobs 指标 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 警报,用于监控 Job SampleotaJob 在给定时间段内失败的任务执行次数。然后,在该时段内有超过 5 个任务执行失败时,它会通知您。警报通过每 3600 秒检查报告值来监控 Jobs 指标 FailedJobExecutionCount。它在单个报告值大于 5 时激活,这意味着过去 1 小时内失败的任务执行数超过了 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