Monitoring SQL Server 2008 R2 cluster state

Source: Internet
Author: User
Tags getdate

DECLARE @OutputType varchar (20)
DECLARE @debug char (1)
Declare @ForceRefresh char (1)
Declare @xp_cmdshell_available char (1)

Set @OutputType = ' LIST '
Set @Debug = ' Y '
Set @ForceRefresh = ' Y '
Set @xp_cmdshell_available = ' Y '

Begin
SET NOCOUNT ON
DECLARE @id int
DECLARE @id2 int
DECLARE @Line varchar (300)
DECLARE @CurrentCmd varchar (30)
DECLARE @Cmd varchar (300)
DECLARE @Node varchar (100)
DECLARE @Resource varchar (100)
DECLARE @Status varchar (20)
DECLARE @i int
DECLARE @Group varchar (100)
DECLARE @Num varchar (10)
DECLARE @ClusterID int
DECLARE @tmp int
DECLARE @ThisGroupsCurrentNode varchar (100)
Declare @DoneClusterName char (1)
Declare @RunningOnACluster char (1)
DECLARE @Line2 varchar (300)
declare @SQLName sysname
declare @WindowsMachineName sysname
declare @PreferredServer sysname
DECLARE @SQL varchar (4100)
DECLARE @FailCnt int
DECLARE @PreferredServers int
DECLARE @z int
declare @CurrentSQLServerGroup sysname
declare @CurrentSQLServer sysname
DECLARE @QuorumResource varchar (300)
Declare @CreatedTempTables char (1)
DECLARE @LoopGroup varchar (300)
Declare @PreferredServerExists char (1)
If @Debug = ' Y ' Print convert (varchar), GETDATE (), 109) + ': ' + object_name (@ @procid) + ' started. '
Select @DoneClusterName = ' N '

--Verifying @outputtype type
If lower (@OutputType) in (' Q ', ' quick ', ' s ', ' summary ', ' Sum ') Select @OutputType = ' Quick '
else if lower (@OutputType) in (' l ', ' list ') Select @OutputType = ' list '
Else
Begin
Select @Cmd = ' Error in ' + object_name (@ @procid) +
': @OutputType parameter must be ' Quick ' or ' ' List ', not ' +
IsNull (@OutputType, ' <null> ') + '. '
RAISERROR 50001 @Cmd
Return
End

If UPPER (@xp_cmdshell_available) in (' Y ', ')
SET @xp_cmdshell_available = ' Y '
Else
SET @xp_cmdshell_available = ' N '
If @Debug = ' Y ' Print convert (varchar), GETDATE (), 109) + ': Calling Spot_checkcluster ... '
Select @FailCnt = 0, @PreferredServers = 0

--Check whether the xp_cmdshell is open

--declare @LocalTable table (result int, errorcode int)
--INSERT INTO @LocalTable
--Execute Qs_soss58_checkcmdshell
--if 1 <> (SELECT COUNT (*) from @LocalTable where result = 1)

if (0 = (select Value_in_use from sys.configurations where name = ' xp_cmdshell '))
Set @xp_cmdshell_available = ' N '

Select @RunningOnACluster = case when convert (Int,serverproperty (' isclustered ') = 1 Then ' Y ' Else ' N ' end
Set @SQLName = Convert (Sysname,serverproperty (' ServerName '))

Set @WindowsMachineName = Convert (Sysname,serverproperty (' machinename '))

If @Debug = ' Y ' Print convert (varchar), GETDATE (), 109) + ': Create temporary table ... '
CREATE TABLE #w3
(ID int identity,
ParentID int NULL,
Type varchar (.) NULL,
Name sysname NULL,
Otherdata sysname NULL,
Status varchar (a) NULL,
Comment varchar (255) NULL,
Preferredserverexists char (1),
Runningonpreferredserver char (1) NULL,
Controlsthecurrentsqlserver char (1) NULL,
Takeofflinecmd char (1) NULL,
Bringonlinecmd char (1) NULL,
Movegroupcmd char (1) NULL,
Stopmscscmd char (1) NULL,
Startmscscmd char (1) NULL,
Runningonserver sysname NULL,
Sequencer smallint NULL
)

CREATE TABLE #w4 (ID int identity (1,1), group_name varchar (255) NULL)

CREATE TABLE #CmdOutput
(
ID int identity,
Outputline varchar (255) NULL
)
Create unique clustered index #PK_CmdOutput on #CmdOutput (ID)
Select @CreatedTempTables = ' Y '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.