How do I use Azure Monitor to monitor the health of the service?
How do I use Azure Monitor to monitor the health of the service? In view of this problem, today the editor summarizes this article on Azure Monitor monitoring, hoping to help more students who want to solve this problem to find a more simple and easy way.
By default, the change tracking solution collects service changes every 30 minutes, and eggs can be configured to collect them every 10 seconds. It is important to note, however, that this approach refers to tracking changes rather than the current state. That is, if there are no changes, no data will be sent to log analytics.
In the next article, we will focus on monitoring Windows services, but the concept works the same for Linux daemons.
Enable change tracking
If we use GUI, we have two ways to enable change tracking:
Enable from the Log Analytics workspace
Click "workspace summary"-"+ Add"-"Change Tracking" in log analytics:
Click "Change Tracking" to open the description tab, then click create, and enter the automation account information as prompted:
Enable from Automation Account
Click "Change Tracking" in "Automation Account", then select the corresponding log analytics workspace and click enable:
Ps: personally, I find it easier to write by enabling change tracking in an automated account.
Query the collected data
We can list the newly collected data with the following query statement. But please note that, as we said before, we can only collect changed data, not for other states that have not changed. And if the virtual machine suddenly crashes, we may not collect the corresponding change practices. But don't worry, we can use other query statements to monitor the viability of vm.
Let utcoffset = 8h ConfigurationData | where ConfigDataType = = "WindowsServices" | where SvcName = = "W3SVC" | extend localTimestamp = TimeGenerated + utcoffset | project localTimestamp, Computer, SvcDisplayName, SvcState | order by localTimestamp desc | summarize arg_max (localTimestamp, *) by SvcDisplayName
Configure Service change Alerts:
In general operation and maintenance scenarios, we certainly hope that when a problem is detected in the service, we can notify the corresponding operation and maintenance personnel by email and other means to deal with it. So here we can configure the corresponding alert rules according to the service changes. In this example, we use it to query and warn whether the IIS (W3SVC) service is stopped:
ConfigurationChange | where ConfigChangeType = = "WindowsServices" and SvcName = = "W3SVC" and SvcState = = "Stopped"
After setting the alarm, we can manually stop the iis service in the test environment. After the service is stopped, our mailbox will receive the following alert:
This is the end of the method of using Azure Monitor to monitor the health of the service. I hope the above content can be helpful to you and learn more knowledge. If you like this article, you might as well share it for more people to see.