选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

创建要监控的 CloudWatch 警报 AWS IoT

聚焦模式
创建要监控的 CloudWatch 警报 AWS IoT - AWS IoT Core

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

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

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

您可以查看 CloudWatch 警报可以监控的所有指标AWS 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 的失败任务执行总数,SampleOTAJob并在超过 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
隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。