Skip to content

Instantly share code, notes, and snippets.

@EitanBlumin
Created August 20, 2020 08:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save EitanBlumin/5ad388aed80f6eb8774677bc685969c4 to your computer and use it in GitHub Desktop.
Save EitanBlumin/5ad388aed80f6eb8774677bc685969c4 to your computer and use it in GitHub Desktop.
Query to run in the SentryOne database to check your inventory of AlwaysOn Availability Groups
SELECT SiteName, ReplicaName
, NumberOfAvailabilityGroups = COUNT(DISTINCT AGName)
, NumberOfPrimaries = COUNT(DISTINCT PrimaryReplica)
FROM
(
SELECT DISTINCT
ES.ObjectName AS ReplicaName, S.Name AS SiteName
, AG.Name AS AGName
, AG.PrimaryReplica
FROM [SentryOne].[AlwaysOn].[AvailabilityGroup] AS AG
INNER JOIN [SentryOne].[AlwaysOn].[AvailabilityGroupReference] AS AGR ON AGR.GroupID = AG.GroupID
INNER JOIN [SentryOne].[dbo].[EventSourceConnection] AS ES ON AGR.EventSourceConnectionID = ES.ID
LEFT JOIN [SentryOne].[dbo].[Device] AS D ON ES.DeviceID = D.ID
LEFT JOIN [SentryOne].[dbo].[Site] AS S ON D.SiteID = S.ID
) AS q
GROUP BY
SiteName, ReplicaName
ORDER BY
SiteName ASC, ReplicaName ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment