Free Newsletters:
DatabaseDaily  
Database Journal
Search Database Journal:
 
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» DBA Jobs
» Sitemap

News Via RSS Feed


follow us on Twitter





Brocade Doubles Down on 16 Gbps Fibre Channel

Microsoft Wants iOS Apps to Run on WP7

Avaya Debuts New Virtual Services Switch
Database Journal |DBA Support |SQLCourse |SQLCourse2







Technical Specialist – Pre-sales (MA)
Next Step Systems
US-MA-Littleton

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

MS SQL

May 5, 2004

Checking SQL Server's Heart Beat

By Muthusamy Anantha Kumar aka The MAK

It is imperative to have monitoring tools to monitor the services running in a windows operating system based server. However, small shops do not have that kind of budget to get tools for monitoring. Data Base Administrators should be notified as soon as one of the SQL Server services is stopped, restarted or not responding. In this article, I am going to discuss how to check all SQL server services from one location and how to check the heart beat of SQL Server instances every few minutes.

Method1

This method is useful for Database administrators to check the heart beat of SQL Server services daily.

Step1

Create a folder c:\HeartBeat and create a file ServiceList.txt as shown below with all the servers and services you would like to check.

SQL,MSSQLServer
SQL,SQLSERVERAGENT
YUKON,MSSQLServer
YUKON,SQLSERVERAGENT
YUKON,MSSQLServerOLAPService
ETL,MSSQLServer
ETL,SQLSERVERAGENT

Note: Add your server names and the corresponding service names.

Step2

Create a file c:\HeartBeat\CheckHeartbeat.vbs and copy and paste the below code into the file.

'Objective: TO check the Heartbeat of all SQL Server services
'Author: MAK
'Date: April 2, 2004

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 shown below indicates that the script has completed.

In addition, it creates a file c:\HeartBeat\Status.txt as shown below.

4/8/2004 1:03:46 AM
ServerName: SQL
ServiceName: MSSQLServer
Status: OK
State: Running
4/8/2004 1:03:47 AM
ServerName: SQL
ServiceName: SQLSERVERAGENT
Status: OK
State: Stopped
4/8/2004 1:03:47 AM
ServerName: YUKON
ServiceName: MSSQLServer
Status: OK
State: Running
4/8/2004 1:04:02 AM
ServerName: YUKON
ServiceName: SQLSERVERAGENT
Status: OK
State: Running
4/8/2004 1:04:03 AM
ServerName: YUKON
ServiceName: MSSQLServerOLAPService
Status: OK
State: Running
4/8/2004 1:04:03 AM
ServerName: ETL
ServiceName: MSSQLServer
Error: 462
Error: The remote server machine does not exist or is unavailable
4/8/2004 1:04:08 AM
ServerName: ETL
ServiceName: SQLSERVERAGENT
Error: 462
Error: The remote server machine does not exist or is unavailable

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 



Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Script Component: Working with BLOB 0010 4 January 27th, 03:03 PM
Will an MS SQL db table trigger affect the value returned by scope_identity? wreade 2 December 19th, 04:48 PM
BULK UPDATE error benedec 1 December 14th, 08:39 AM
Toggling problem in Matrix report ssrs 2008 dev_ritesh 0 December 2nd, 02:17 PM