Monitoring the health of an Availability Group
In this recipe, we will see a few snippets that will help us monitor the health of an AlwaysOn Availability Group.
Getting ready
To follow this recipe, your AlwaysOn availability group should already be set up and the primary/secondary replicas should be functional. If not, you can use the previous recipes in this chapter to set up your AlwaysOn Availability Group.
In PowerShell, there are three cmdlets that we will use to test AlwaysOn health. To use these cmdlets, you need the following permissions:
CONNECT
VIEW SERVER STATE
VIEW ANY DEFINITION
How to do it...
We will see how to monitor an Availability Group's health using PowerShell by following these steps:
Open PowerShell ISE as an administrator.
Add the following script and run it:
Import-Module SQLPS -DisableNameChecking $instanceName = "SQL01" $AGName = "SQLAG" #SMO server object $server = New-Object Microsoft.SqlServer.Management.Smo.Server $instanceName #test availability group health...