Quantcast
Channel: THWACK: All Content - Server & Application Monitor
Viewing all articles
Browse latest Browse all 12281

SQL Mirror Monitor using TSQL or Powershell

$
0
0

,1. I saw these previous posts about monitoring SQL Mirrors in SolarWinds

http://thwack.solarwinds.com/message/168142#168142

http://thwack.solarwinds.com/message/165415#165415


2. Then I thought of using SolarWinds "SQL Server End User Experience Monitor" to execute a TSQL statement to pull back the status of the servers mirrors.

You could run a query like the following:

-- TSQL Query to show Mirror status
Select db.name, m.mirroring_role_desc, mirroring_partner_instance, Mirroring_partner_name, mirroring_state_desc
FROM sys.database_mirroring m
join sys.databases db
on db.database_id=m.database_id
Where mirroring_role_desc='PRINCIPAL'
or mirroring_role_desc='MIRROR'
order by mirroring_role_desc DESC
Go

 

But that gives you too much info, so I reduced the above to just to ge the db name and the status:
Select db.name, mirroring_state_desc
FROM sys.database_mirroring m
join sys.databases db
on db.database_id=m.database_id
Where mirroring_role_desc='PRINCIPAL'
or mirroring_role_desc='MIRROR'
order by mirroring_role_desc DESC
Go

 

Your output would look like:
name   mirroring_state_desc
Your_DBName1  SYNCHRONIZED
Your_DBName2  SYNCHRONIZING
Your_DBName3  SUSPENDED
Your_DBName4  DISCONENCTED

 

But if I recall SolarWinds requires the 'output value' of a query value to be a number, so I dont think you can display 'Synchronized' 'Suspended' ... etc.

See Mirror states at  http://technet.microsoft.com/en-us/library/ms189284(v=sql.105).aspx

 

So lets use a different query where a number would represent a miror state
-- see Mirroring states at http://technet.microsoft.com/en-us/library/ms178655.aspx


Select db.name, mirroring_state
FROM sys.database_mirroring m
join sys.databases db
on db.database_id=m.database_id
Where mirroring_role_desc='PRINCIPAL'
or mirroring_role_desc='MIRROR'
order by mirroring_role_desc DESC
Go

 

Your output would now look like:


name   mirroring_state
Your_DBNAme1  0
Your_DBNAme2  1
Your_DBNAme3  2
Your_DBNAme4  3
Your_DBNAme4  4
Your_DBNAme4  5

 

The mirroring_state numbers above represent the following:
0 = Suspended
1 = Disconnected from the other partner
2 = Synchronizing
3 = Pending Failover
4 = Synchronized
5 = The partners are not synchronized. Failover is not possible now

 

So now need to create a "SQL Server End User Experience Monitor" that will allow us to run the above query and return the database names with the mirroring_state number.

 

I'm not 'exerienced' with multi- variable output returns in SolarWinds monitoring yet. 

REQUEST - Can anyone pick up from here with how to do that ?

If we can get this far, then we can have threshholds set up such as:
warning 'less than or equal to'  '3'  (which would catch mirroring in  Suspended, Disconnected from the other partner, Synchronizing, Pending Failover,  states)

critical 'less than or equal to' '1'    (which would catch mirroring in 'Suspended' or 'Disconnected from the other partner', states)

--or--
Critical 'not equal to' 4 (which would show any state other than 'Synchronized')

 

2nd Option:
***********
Another option would be to use Powershell to check the status of the mirroring and 'borrow' code from

' http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436/

and modify it to show only the database name and the 'mirroring_state' in a SolarWinds 'Windows PowerShell Component Monitor '.

(maybe modify 'MirroringStatus' below to 'Mirroring_State' or 'MirroringState' ? )

 

# Load SMO extension
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null;

 

# Servers to check
$sqlservers = @("server1", "server2", "server3");
foreach($server in $sqlservers)
{
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server;
# Get mirrored databases
$databases = $srv.Databases | Where-Object {$_.IsMirroringEnabled -eq $true};
Write-Host $server;
Write-Host "==================================";
$databases | Select-Object -Property Name, MirroringStatus | Format-Table -AutoSize;
}

I'm not 'experienced' with multi- variable output returns in SolarWinds monitoring yet. 

REQUEST - Can anyone pick up from here with how to do that ?

If we can get this far, then we can have threshholds set up such as:
Warning 'less than or equal to'  '3' (which would catch mirroring in  Suspended, Disconnected from the other partner, Synchronizing, Pending Failover,  states)

Critical 'less than or equal to' '1'    (which would catch mirroring in Suspended or Disconnected from the other partner, states)

--or--
Critical 'not equal to' 4 (which would show any state other than 'Synchronized')

 

** This post is a question - am I on the right track?  Can anyone point me in a direction on how to set up

a multi output monitor in 'Windows PowerShell Component Monitor' or 'SQL Server End User Experience Monitor'

If you found a post on thwack that gives and example please post a url link to it here.

Or if you have a page number for me to reference on either of the two following resoureces:

http://www.solarwinds.com/documentation/apm/docs/APMAdministratorGuide.pdf

http://www.solarwinds.com/documentation/apm/docs/SAMAdminGuide.pdf


Viewing all articles
Browse latest Browse all 12281

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>