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
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted 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


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: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date