Monday, October 16, 2023
HomeIoTMonitoring your IoT fleet utilizing CloudWatch

Monitoring your IoT fleet utilizing CloudWatch


On this weblog we are going to present you the best way to monitor your IoT (Web of Issues) fleet and alert when situations attain or exceed regular thresholds that you just contemplate to be regular operational limits. We are going to undergo the steps to setup Amazon CloudWatch dashboards primarily based on AWS IoT metrics, create alarms from metrics, after which question log knowledge to realize further insights into your fleet exercise or help in troubleshooting.

As per the AWS Properly-Architected Framework, after you implement your workload, you should monitor its efficiency in an effort to remediate any points earlier than they affect your prospects. Monitoring metrics ought to be used to boost alarms when thresholds are breached.

Amazon CloudWatch is a monitoring and observability service that gives you with knowledge and actionable insights to observe your workload, reply to system-wide efficiency adjustments, optimize useful resource utilization, and get a unified view of operational well being. CloudWatch collects monitoring and operational knowledge within the type of logs, metrics, and occasions from workloads that run on AWS and on-premises servers.

The steps we are going to comply with to setup our IoT monitoring are:

  1. Stipulations
  2. Allow logging for AWS IoT Core
  3. Create a CloudWatch dashboard
  4. Create customized IoT alarms and metrics
  5. View customized metrics and create alarms
  6. Troubleshoot a difficulty that created the alert

Stipulations

The steps on this weblog will use the AWS Command Line Interface (AWS CLI) for demonstration functions. To configure primary settings please discuss with the AWS CLI Fast setup.

Allow logging for AWS IoT Core

You may configure AWS IoT logging by utilizing the AWS Administration Console, AWS Command Line Interface (AWS CLI), or the AWS IoT Core API. With the intention to configure logging for particular factor teams or particular units you have to to make use of the AWS CLI or the IoT Core API.  For extra data, please discuss with IoT Machine Logging.

Use the set-v2-logging-options command to set the logging choices on your account.

aws iot set-v2-logging-options
--role-arn <logging-role-arn>
--default-log-level <log-level>

Log-levels:
ERROR – Any error that causes an operation to fail. Logs embrace ERROR data solely.
WARN – Something that may probably trigger inconsistencies within the system, however may not trigger the operation to fail. Logs embrace ERROR and WARN data.
INFO – Excessive-level details about the move of issues. Logs embrace INFO, ERROR, and WARN data.
DEBUG – Data that is perhaps useful when debugging an issue. Logs embrace DEBUG, INFO, ERROR, and WARN data.
DISABLED – All logging is disabled.

Along with factor teams, you too can log targets corresponding to a tool’s consumer ID, supply IP, and principal ID.

  • Factor group
  • Machine degree (Consumer ID, Supply IP, principal ID)

Utilizing the set-v2-logging-level command to configure resource-specific logging.

aws iot set-v2-logging-level
–log-target targetType=THING_GROUP, targetName=<thing_group_name>
–log-level <log-level>

Within the following instance the logging degree for a single system with the clientID beta_device123 has been set to DEBUG:

aws iot set-v2-logging-level
--log-target "{"targetType":"CLIENT_ID","targetName":"beta_device123"}"
--log-level DEBUG

Adjusting the log-level to INFO or DEBUG for particular factor teams is helpful when deploying new options or firmware. After a profitable deployment you drop the log-level again to your normal logging degree.

AWS IoT Monitor dashboard

The Monitor dashboard permits you to view CloudWatch metrics for AWS IoT from all units registered in your AWS account. On this dashboard under, you’ll be able to see the variety of messages printed and acquired by your units aggregated by protocol, kind, and path, the variety of messages printed by your units over time, and different metrics. It’s out there within the monitor part of the AWS IoT Core web page within the AWS console.

Image of default IoT monitor

Create a CloudWatch dashboard

Amazon CloudWatch (CloudWatch) dashboards are customizable house pages within the CloudWatch console that you should utilize to observe your sources in a single view, even these sources which can be unfold throughout completely different Areas.

If you work together with AWS IoT, the service sends the next metrics to CloudWatch each minute.

  • Rule metrics
  • Message dealer metrics
  • Machine provisioning metrics
  • Fleet indexing metrics

Contemplate organising a dashboard that features metrics which can be vital to your deployment. For instance, you probably have a fleet with a gradual messaging fee together with an anticipated variety of IoT Rule executions you could possibly have them as a part of your dashboard. One other dashboard might show the standing of IoT jobs deployed to your fleet displaying the variety of queued jobs, profitable jobs, and failed jobs. As your fleet adjustments over time, the dashboards could should be up to date to replicate the brand new standing or metrics on your fleet.

Within the CloudWatch metrics image under you’ll be able to see an examples of AWS IoT metrics. For this particular area the CloudWatch is retrieving metrics for the variety of units efficiently registered, certificates creation associated metrics, and the variety of occasions units didn’t provision on account of a consumer aspect or server aspect error.

CloudWatch metrics showing claim certificates and other IoT metrics

Now, under you’ll be able to see how a person can flick thru the out there metrics and add it to a dashboard. On this case, choose the precise certificates Id, then click on Add to dashboard utilizing the drop-down Actions menu on the high proper.

This shows what number of Issues have been registered efficiently on the chosen time interval window of 1 hour. You may change this to completely different interval time frame.

How to add metrics to the dashboard by selecting the metric in lower pane then clicking add to dashboard using drop-down action menu at the top right.

Under is a customized made dashboard created in Amazon CloudWatch with the fundamental metrics on your fleet of IoT units. This can be utilized by the operations groups to grasp the standing of the fleet.

Custom CloudWatch dashboard with metrics to monitor your fleet.

Create customized AWS IoT metrics

AWS IoT sends many normal metrics and dimensions to CloudWatch.  You too can search and filter the log knowledge coming into CloudWatch Logs by creating a number of metric filters. Metric filters outline the phrases and patterns to search for in log knowledge as it’s despatched to CloudWatch Logs. CloudWatch Logs makes use of these metric filters to show log knowledge into numerical CloudWatch metrics that you would be able to graph or set an alarm on.

Within the Amazon CloudWatch Console, within the left aspect navigation pane, broaden Logs and choose Log Teams. Click on the AWSIotLogsV2 log group.

Within the under image you’ll be able to see the AWSIoTLogsV2 Log group element.

CloudWatch Log groups selecting AWSIotLogsV2

Click on the Search Log Group button and kind the search string under into the filter occasions dialog field and select half-hour because the time interval. For extra data on the best way to question log occasions in CloudWatch discuss with Search log knowledge utilizing filter patterns – Amazon CloudWatch Logs.

Sort the next into the search field.
{ $.eventType = RuleExecution && $.standing = Failure }

Image showing where to add the search query

Under we now have an instance of a number of failed rule executions over the previous half-hour.

Image showing the results of the log group query

Click on on the Create Metric Filter button to create a metric primarily based on this search sample. Within the image under, I’m naming the filter one thing descriptive and likewise creating a brand new metric namespace known as MyIotApplication.

As you add extra metrics you’ll be able to group them by software, workload, initiatives, or any grouping that your group has chosen. The metric worth is about as one, as it’s despatched to the metric filter every time the filter sample matches. Different fields are left at default. Click on the Create button to proceed. As soon as this metric filter has been created you should utilize it simply as you’d different CloudWatch metrics by including it to a graph, dashboard, or creating an alarm.

Create metric filter dialog box

View customized metrics and create alarms

Now we navigate to the CloudWatch console and choose All Metrics from the left aspect menu. In the principle window choose the Browse tab and you will notice the brand new customized namespace you simply created. On this instance it’s known as MyIotApplication. Click on on the MyIotApplication hyperlink then the Metric with no dimension. The output under reveals the variety of failed rule executions over the time interval chosen.

Graph showing failed rule executions over time.

By clicking on the Graphed Metrics tab and you will notice extra particulars concerning the metric and mean you can change the kind of graph, time interval, and extra. You may add this metric to your dashboard or a brand new dashboard utilizing the Motion drop down button on the high proper of the display screen.

You too can click on on the bell icon to create an alarm. Let’s do this now.

Showing the alarm icon used to create an alarm from this metric

After clicking the bell icon, you will notice the next kind which is able to mean you can make changes to the alarm configuration.

Form that allows you to adjust the metric alarm configuration

This lets you set thresholds on your alarm. We are going to set a threshold of two or higher inside 5 minutes. Underneath Extra configuration go away these at default. This permits the alarm to return to a traditional state if the brink worth drops under the alarm threshold for one time frame—on this case 5 minutes.

Click on Subsequent and choose an Amazon Easy Notification Service (Amazon SNS) subject that may obtain the notification when in an ALARM state. This assumes you’ve gotten already configured an Amazon SNS subject. Extra data may be learn in Creating an Amazon SNS Matter.

Form showing configuration options for the alarm notifications

Choose a reputation on your alarm and click on Subsequent.

Form to set the name and description of the alarm

On the following display screen click on on the Create Alarm if every part seems to be appropriate. Your alarm is now created.

You may take a look at your alarm and notifications by setting the alarm to ALARM utilizing the AWS CLI. Under we present the instructions to set the alarm to ALARM and again to OK.

aws cloudwatch set-alarm-state --alarm-name IoTRuleExecutionFailures --state-reason "testing alarm" --state-value ALARM

aws cloudwatch set-alarm-state --alarm-name IoTRuleExecutionFailures --state-reason "testing alarm" --state-value OK

Troubleshoot a difficulty that created an alert

Subsequent, we present the steps you could possibly carry out when you’ve gotten an alarm or system habits that’s outdoors of anticipated thresholds. CloudWatch Logs and CloudWatch Logs insights present highly effective search capabilities to help you in figuring out doable root causes of the alarms or surprising behaviors.

AWS IoT logs are saved within the AWSIotLogsV2. When you navigate to this log group you will notice the occasions saved in varied log streams. By clicking on the Search log group button you’ll be able to filter these logs by question and time-frame.

Search log group button

If you’re anticipating guidelines to be evaluated and actions to be carried out you’ll be able to confirm this by filtering for occasion kind RuleMatch as follows:

{ $.eventType = RuleMatch }

If you wish to seek for any guidelines which have failed up to now half-hour I might add the next to the filter subject. This instance reveals the best way to filter for RuleExecution occasions, however solely the occasions which have a standing of failure:

{ $.eventType = RuleExecution && $.standing = Failure }

CloudWatch logs Insights allow you to interactively search and analyze your log knowledge in CloudWatch logs. You may carry out queries that can assist you extra effectively and successfully reply to operational points. If a difficulty happens you should utilize CloudWatch Logs Insights to establish potential causes and validate deployed fixes.

CloudWatch Log Insights can be utilized as a device that can assist you perceive patterns of utilization. Let’s take an instance the place you wish to checklist the highest 10 matters being printed to.

fields @timestamp, topicName
| stats rely(*) as numPublishIn by (eventType="Success") , topicName
| type numPublishIn desc
| restrict 10

High 50 Publishers by clientID

filter eventType="Publish-In"
| stats rely(*) as numPublishIn by clientId
| type numPublishIn desc
| restrict 50

CloudWatch Log Insights permits you to construct queries in opposition to the logs. When you acquired a connection throttle alert chances are you’ll wish to run a question to point out the purchasers with the best variety of connections through the previous half-hour:

filter eventType="Join"
| stats rely(*) as NumConnections by clientId
| type NumConnections desc
| restrict 20

Log Insights showing the number of connections by clientID over time

Conclusion

Monitoring is a continuing course of. As your fleet and options evolve, you have to to replace your monitoring objectives and thresholds. By monitoring your fleet and setting alarms you may be proactive as a substitute of reactive. On this weblog publish you discovered how AWS gives completely different choices to observe your fleet of units. We confirmed utilizing each automated instruments and handbook monitoring instruments the place you allow logging, create dashboard with the built-in metrics, create customized metrics and alarms. Lastly, we confirmed the best way to troubleshoot when the system habits adjustments.

Additional studying may be discovered right here on Amazon CloudWatch Designing and implementing logging and monitoring with Amazon CloudWatch and extra IoT Finest Practices Blogs right here.

Authors

Steve KremsSteve Krems is a Specialist Answer Architect for IoT at Amazon Net Providers (AWS). Previous to this function, Steve spent 18 years within the semiconductor trade in Data Know-how administration roles with a give attention to cloud migration and modernization.
Sunitha EswaraiahSunitha Eswaraiah is a Options architect at AWS supporting prospects in Nordics. She has 10+ years of expertise as an information engineer and as a again finish developer. Now she began to concentrate on constructing IoT options. Previous to AWS, she labored for Gartner and Verizon in India.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments