Tanmaya Thopate, Chincholi Morachi, Low cost WEBSITE development in Pune, Windows Tips n Tricks

Friday, November 14, 2008

Check heart beat of SQL Server services

Helpful for Database administrators to test the heart beat of SQL Server services daily.

Step1
Create c:\HeartBeat folder and a file ServiceList.txt which will contains following text in it with all the servers and services would like to check.

SQL,MSSQLServer
SQL,SQLSERVERAGENT
YUKON,MSSQLServer
YUKON,SQLSERVERAGENT
YUKON,MSSQLServerOLAPService
ETL,MSSQLServer
ETL,SQLSERVERAGENT
Note: Need to add server names and its related service names.

Step2
Make a file c:\HeartBeat\CheckHeartbeat.vbs and copy the below code into the file.

'Objective: TO check the Heartbeat of all SQL Server services

on error resume next
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")

InputFile="c:\Heartbeat\Servicelist.txt"
Outputfile="c:\Heartbeat\Status.txt"

Set ifile = iFSO.OpenTextFile(inputfile)
Set ofile = ofso.createTextFile(OutputFile, True)

Do until ifile.AtEndOfLine
servicelist= ifile.ReadLine
strcomputer=left(servicelist,instr(servicelist,",")-1)
Service =right(servicelist,len(servicelist)-instr(servicelist,","))
ofile.writeline Now()
ofile.writeline "ServerName: " & strcomputer
ofile.writeline "ServiceName: " & Service

Set objWMIService =nothing
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

if err.number<>0 then
ofile.writeline "Error: " & err.number
ofile.writeline "Error: " & err.description
else

Set colItems = nothing
query=""
query = "Select * from Win32_Service where name = '" & Service & "'"
'msgbox query
Set colItems = objWMIService.ExecQuery(query,,48)
if err.number<>0 then
ofile.writeline "Error: " & err.number
ofile.writeline "Error: " & err.description
else
For Each objItem in colItems
ofile.writeline "Status: " & objItem.Status
ofile.writeline "State: " & objItem.State
next

next
end if
end if
err.number=0
Loop

msgbox "SQL Service Status Check completed"
Step3
Execute the above VB script. The message will show the status of it.
In addition, it creates a file c:\HeartBeat\Status.txt with detailed logs for the status.

Ref: Check MSSQL Server's status
 
Add to Technorati Favorites